Install Docker and Run Your First Container

Harry · 14 Sep 2026 · 3 views
Advertisement
Advertisement

Install Docker

On Windows and macOS, install Docker Desktop from docker.com – it bundles the engine, CLI and a dashboard. On Linux, install Docker Engine from your distribution’s repository. Verify the install:

docker --version
docker run hello-world

The hello-world image prints a confirmation message and exits. If you see it, the daemon is running and can pull images.

Run something useful

Let’s run the Nginx web server. The -d flag runs it detached (in the background), -p maps a host port to the container port, and --name gives it a friendly name:

docker run -d -p 8080:80 --name web nginx

Open http://localhost:8080 and you will see the Nginx welcome page – served from inside a container you did not have to install.

Inspecting running containers

docker ps                 # list running containers
docker logs web           # view the container's output
docker exec -it web bash  # open a shell inside the container

docker exec -it is the command you will use constantly: it runs a process (here, an interactive bash shell) inside an already-running container so you can look around its filesystem.

Stopping and cleaning up

docker stop web     # graceful stop
docker rm web       # remove the stopped container
docker ps -a        # list ALL containers, including stopped ones
docker images       # list images on your machine

Key points

  • docker run pulls the image if needed and starts a container.
  • -d detaches, -p host:container maps ports, --name names it.
  • ps, logs and exec -it are your daily inspection tools.
  • Stopped containers linger until you rm them – check with ps -a.
Share this post:

Comments (0)

Please login or register to comment.