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:

  • Default docker machine on Mac
  • How to share a folder between my Mac and a Docker container
  • How to extend existing docker container?
  • Docker “Gracefully stopping” itself during `docker-compose up` but not `docker-compose run --entrypoint`
  • How to mount HDFS in a Docker container
  • how to get docker-compose to use the latest image from repository
  • 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?

  • crontab not executing on centos7 container
  • Get elastic beanstalk environment variables in docker container
  • Django migrations with Docker on AWS Elastic Beanstalk
  • Forwarding traffic between two interfaces
  • How to maintain sticky session(session persistence) with docker swarm?
  • Gitlab-runner with syntax error
  • 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.