WORKDIR
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.
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
| Category | Docker |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |