appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Containers and images

Lesson 1 of 49 minBeginner

What a container is and how to run one.

A container is an isolated process that carries everything it needs: code, runtime and libraries. It starts in seconds and behaves the same on your laptop and on a server. It is not a full virtual machine: containers share the host kernel.

  • Image: a read-only template (for example nginx or python:3.12).
  • Container: a running instance of an image.
  • Registry: where images are stored, such as Docker Hub.

Run your first container

docker run hello-world                       # downloads the image if needed, runs it, exits
docker run -d -p 8080:80 --name web nginx    # run in background, map host port 8080 to container port 80
docker ps                                    # running containers
docker ps -a                                 # including stopped ones
docker logs web                              # output of the container
docker stop web && docker rm web             # stop and remove it

After the nginx command, open http://localhost:8080 to see the web server. -p HOST:CONTAINER maps ports.

Images

docker pull python:3.12      # download an image
docker images                # list local images
docker rmi python:3.12       # remove an image

NoteAlways use a specific tag such as python:3.12 instead of relying on latest, so builds are repeatable.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

HintLike the Linux ps command.
HintFlags -d and -p HOST:CONTAINER.
3. What is the difference between an image and a container?
4. Do containers include their own operating system kernel?

Key terms