How to RUN docker commands inside a folder

How using a Dockerfile can I RUN all commands within a folder home?

For example, in Docker I have the following where I have to CD into the folder before running the second command:

  • Connection issue with Jenkins within Docker on RaspberryPi 3 (rpi-jenkins) when cloning a Bitbucket Git Repo
  • Running cron within a docker debian:jessie container
  • Ensure nginx master process stays running
  • Why docker 1.11.0 use too much disk space on /run/docker/libcontainer?
  • Run project dependencies commands from dockerfile
  • Tilde Expansion Doesn't Work in Docker COPY Command
  • RUN cd /var/sites/demo && virtualenv env --system-site-packages
    RUN cd /var/sites/demo && pip install -r requirements.txt

    Is there a way I can remove the cd /var/sites/demo and have each command run from that location?

  • Is it possible to restrict access to lxc containers?
  • How do a see the “ancestor tree” of a docker-compose file
  • Jenkins - Pipeline (Amazon EC2 Container Service Plugin)
  • Generation of pdf PDFBox headless docker container fails
  • Conventional way to resolve docker derived image build time vs. image size tradeoff
  • docker container can't use `service sshd restart`
  • One Solution collect form web for “How to RUN docker commands inside a folder”

    By setting WORKDIR to the appropriate path:

    From the Dockerfile Reference:

    The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.

    So your file should have:

    WORKDIR /var/sites/demo

    Before your RUN commands.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.