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:

  • Re-build Go (App Engine) app running inside docker container?
  • gitlab in docker behind traefik proxy fails (usually)
  • Installing Docker with sudo
  • No access permission error with npm global install on docker image
  • Why can't the Docker (“master”) container see workers?
  • Docker: how to get back to initial directory after issuing a WORKDIR 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?

  • Docker container doesn't start due to CMD and ENTRYPOINT
  • docker-compose up is starting the container and immediately stopping them
  • Docker env variables not set while log via shell
  • can't run docker image of jhipster webapp
  • Connect to docker container as user other than root
  • Deploying WAR file in Docker container
  • 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.