MarkK
MarkK

Reputation: 1088

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:

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?

Upvotes: 2

Views: 1267

Answers (1)

Dimitris Fasarakis Hilliard
Dimitris Fasarakis Hilliard

Reputation: 160667

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.

Upvotes: 3

Related Questions