Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker WORKDIR - on my machine or the container?

What context does the WORKDIR keyword in a Dockerfile refer to? Is it in the context I run docker build from or inside the container I am producing?

I find myself often putting RUN cd && ... in my docker files and am hoping there's another way, I feel like I'm missing something.

like image 394
jsarbour Avatar asked Feb 03 '23 18:02

jsarbour


1 Answers

It is inside the container.

Taken for the Dockerfile reference site https://docs.docker.com/engine/reference/builder/#workdir

The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn’t exist, it will be created even if it’s not used in any subsequent Dockerfile instruction.

So rather than adding RUN cd && ... you could do:

WORKDIR /path/to/dir
RUN command
like image 72
markybb41 Avatar answered Feb 06 '23 09:02

markybb41