Ad space (banner)
AD

Got the fundamentals? A structured Docker course is a fast way to level up.

Find Docker courses on Udemy

Affiliate link. Costs you nothing extra.

🐳Docker Lessons
Lesson 28 / 45

Setting the Working Directory with WORKDIR

When you want to decide where inside the image your files live and commands run, use WORKDIR. It sets the working directory for every instruction that follows.

The syntax is WORKDIR /path. The directory is created if it does not exist.

Writing WORKDIR /app means later COPY and RUN instructions operate inside /app, and the container also starts there.

A common stumble is using RUN cd /app instead. Each RUN is its own layer, so the directory change doesn't carry over — WORKDIR is the instruction that persists.

In real work, setting a clear working directory keeps paths predictable and the Dockerfile readable.

Docker
Try it (type this into the pseudo terminal)
docker build -t myapp .

🧑‍💻 You can type this command into the Docker pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)