When docker build does a RUN command, what "environment" is it running in?

Explaining the question, does it run at build time, or when the container starts? Is it using the operating system mentioned in the FROM?


In the Dockerfile, the RUN step is performed during the docker build process. The operating system is shared with the host (containers != VMs). The filesystem and rest of the configuration used to define the temporary container is based on the state of the image resulting from the previous step. Each step in the Dockerfile extends the image with additional metadata and filesystem layers.

The RUN step itself is performed inside a temporary container. The output of the RUN step is any filesystem changes that exist in the container at the time the command exits successfully. Changes to the shell (like a cd command or setting an environment variable inside the shell), spawned processes, and changes to files inside a Volume are all discarded. The changes to the container filesystem are captured as a filesystem layer that is included in the resulting image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.