Emmanuel Courreges
Emmanuel Courreges

Reputation: 878

Docker: how to get back to initial directory after issuing a WORKDIR command

There is no explanation in docker doc or seemingly any builtin variable in docker to find the original working directory where the image is being built. I want to run commands on different directories and at some point get back to where i launched docker build from. Am I missing something obvious? Thanks.

Dockerfile example:

FROM ubuntu
WORKDIR /my_folder
RUN command1
WORKDIR ??? // How do i get back to the Dockerfile folder?
RUN command2

Upvotes: 25

Views: 18876

Answers (1)

larsks
larsks

Reputation: 312283

The WORKDIR directive is really just cd for your Dockerfile.

Your original working directory inside the container is /. You can get back there by:

WORKDIR /

Remember, this is affecting the context of the containerized build environment, and has nothing to do with where your Dockerfile is located.

Upvotes: 27

Related Questions