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:

  • Pulling images from private registry in Kubernetes
  • Dockerfile: Setup SSH key for Bitbucket
  • Unable to access web application in Docker container via container's ip and exposed port over http
  • why vagrant 1.6 + docker keep asking password for ssh connection
  • Port forwarding: docker -> vagrant -> host
  • How to restore a .sql.gz dump on a Docker MySQL instance?
  • 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?

  • Connect to Tornado app in Docker
  • X509CertificateValidationMode not working in Linux?
  • Docker bridge network, HTTP calls between containers VERY slow (after docker upgrade)
  • Publish to random host port while using --network=host
  • Docker runs of “pip install” and “npm install” on same container overwriting each other
  • Why is a shell within a docker container showing dmesg content from the host?
  • 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.