<p>In the Dockerfile, the <code>RUN</code> step is performed during the <code>docker build</code> 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.</p>

<p>The <code>RUN</code> step itself is performed inside a temporary container. The output of the <code>RUN</code> step is any filesystem changes that exist in the container at the time the command exits successfully. Changes to the shell (like a <code>cd</code> 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.</p>

CC BY-SA 4.0
2018-09-02T00:18:00.983Z
2018-09-02T00:18:00.983Z
BMitch
<p>When docker build does a RUN command, what "environment" is it running in? </p>

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

<docker><dockerfile>
what environment does a build "RUN" run in?
matchingmoments
# what environment does a build "RUN" run in?

(Asked by: username_0 on 2018-09-01)

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?

**Tags:** docker, dockerfile


---

## 1 answers

### Answer by username_1 on 2018-09-02. Score: 3

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.


---

