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 30 / 45

Executing Commands with RUN

When you need to install packages or prepare the image, use RUN. It executes a command at build time and bakes the result into the image.

The syntax is RUN command. Each RUN creates a new layer.

Writing RUN npm install installs the dependencies during the build, so they are already present when the container starts.

A common stumble is confusing RUN with CMD. RUN happens while building the image; CMD happens when the container starts.

In real work, related commands are chained with && into a single RUN to reduce the number of layers and keep the image lean.

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)