Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

Docker for Beginners: What Actually Happens When You Dockerize an Application?

A few days ago, I started learning Docker. Like many beginners, I started with the commands: docker build docker run docker ps docker images But after seeing a few commands, I realized something. I could memorize them. But I didn't really understand what was happening behind them . What exactly is a Docker image? What is a container? Why do we need a Dockerfile? What does docker run actually do?…

Learning Docker can be tricky at first, especially for beginners. It's easy to memorize commands like `docker build`, `docker run`, `docker ps`, and `docker images`, but understanding what's happening behind them is crucial. To truly grasp Docker, it helps to follow a simple application and observe what happens at each step.

Imagine you're working on a Node.js application. After cloning the project and installing dependencies, you start it with `npm install npm start`, and everything works fine. However, if another developer clones the same project and runs `npm install npm start`, it might not work due to differences in Node.js versions, dependencies, or configuration. This is where Docker becomes useful.

Docker allows you to describe how your application should be packaged, instead of relying on everyone to manually recreate the environment. The basic idea is simple: you package your application, its dependencies, and the required environment into a Docker image, which is then used to create a container that runs your application.

To do this, you create a file called Dockerfile, which contains instructions for building your application's environment. Here's a simple Dockerfile for a Node.js application:

```

FROM node:22

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD [ "npm", "start" ]

```

This Dockerfile starts with a Node.js image (`FROM node:22`), sets `/app` as the working directory (`WORKDIR /app`), copies the `package.json` file and installs dependencies (`RUN npm install`), copies the rest of the application code (`COPY . .`), exposes port 3000 (`EXPOSE 3000`), and finally specifies the command to start the application (`CMD [ "npm", "start" ]`).

Now, when you build the Docker image with `docker build -t my-app .`, it reads the Dockerfile and creates a Docker image named `my-app`. The image is a reusable package containing your application and its environment. However, it's not yet a running application. To create a container and run your application, you use the `docker run` command:

```

docker run -p 3000:3000 my-app

```

This command creates a container from the `my-app` image and maps port 3000 from the container to port 3000 on your computer (`-p 3000:3000`). Now, you can access your application by going to `http://localhost:3000`.

So, what's the difference between an image and a container? An image is a reusable package that contains your application and its environment, while a container is a running instance of that image. You can create multiple containers from a single image, each running independently.

In summary, Docker provides a way to package and run applications consistently across different environments. By using Dockerfile, Docker images, and Docker containers, you can ensure that your application runs smoothly, regardless of the underlying system.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Shares in Chinese humanoid robot maker Unitree soar in Shanghai trading debut

HONG KONG (AP) — Shares of Unitree, one of China’s largest humanoid robot makers, initially soared as much as 629% in its public stock trading debut Wednesday…

  • Unitree shares surged 629% in Shanghai STAR market debut
  • Founded in 2016, Unitree raised $904 million in listing
  • Unitree and AGIBOT shipped over 5,000 humanoid robots in 2025

More from Wednesday 19 August →