Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

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
like image 449
Emmanuel Courreges Avatar asked Feb 09 '16 08:02

Emmanuel Courreges


Video Answer


1 Answers

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.

like image 124
larsks Avatar answered Oct 20 '22 20:10

larsks