DELAPARRA
Index
Color
NL
Category: Docker

WORKDIR

Explained by Updated

What is WORKDIR?

WORKDIR: Sets the working directory for subsequent RUN, CMD, COPY, and ENTRYPOINT instructions. Creates it if missing. WORKDIR sets the working folder for the instructions that follow in a Dockerfile, such as RUN, COPY, CMD and ENTRYPOINT. WORKDIR /var/www/html creates the folder if needed and makes it the current directory. It is cleaner than writing cd inside RUN commands, which only lasts for that one command, and it makes relative paths in the rest of the Dockerfile predictable.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about WORKDIR

What should you keep in mind with WORKDIR?

Use absolute paths for WORKDIR, and set it once near the top for your application folder. It also determines where you land when you open a shell in the running container with docker exec, which saves typing during debugging. Combined with COPY . ., it keeps a Dockerfile short and easy to follow.

What does an example of WORKDIR look like?

WORKDIR /usr/src/app

At a glance

CategoryDocker
Explained by
Updated

More Docker terms

All terms starting with W

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.