Skip to main content
In this lesson you’ll run your first Docker containers and explore Docker Hub — Docker’s central registry of prebuilt images you can use to create containers locally. Docker Hub hosts images for many purposes: base operating systems (Ubuntu, Alpine, Debian), web servers (NGINX), databases (Postgres, MySQL, MongoDB), machine learning frameworks (TensorFlow, PyTorch), and more. Choose an image and run it with docker run to create a container. Useful links: Example terminal prompt used below:

What you’ll see in this lesson

  • Pulling small base images (Alpine) and running short commands
  • Running a service image (NGINX) and mapping ports to access it from the host
  • Quick reference for common docker run flags

Try a minimal OS image: Alpine

Alpine Linux is a tiny distribution commonly used for base images. Its small size (a few MB) makes pulls fast and is ideal for lightweight containers. Run Alpine (no command specified):
If the image is not present locally, Docker pulls it first. Example summarized output when pulling:
Note: Running docker run alpine with no foreground process typically exits immediately because the container has nothing to keep it alive. To run a short-lived command inside the container:
This creates a container, runs sleep 10 inside it, and then the container exits after 10 seconds.
Containers remain running only while their main process runs. To explore a container interactively, start a shell with docker run -it --rm alpine sh. The --rm flag removes the container when it exits.
To inspect a file or output non-interactively and remove the container afterwards:
This prints the OS release info, then exits and removes the container.

Run a real application: NGINX

NGINX images are available in several variants (Alpine-based, slim, full) and tagged per version. Run the default NGINX image:
If the image isn’t local, Docker pulls required layers first. Example summarized startup logs:
By default the container listens on port 80 internally. To access the server from your host, publish the container port to a host port:
Then open http://localhost:8080 (or the host IP and port) to see the NGINX welcome page.
When mapping container ports to host ports, be careful exposing services directly to public networks. For production use, secure your service, use firewalls, and control access. Avoid publishing unnecessary ports.

Quick reference: common docker run flags

Next steps

After this introduction, useful topics to learn next include:
  • Image tags and version pinning (use specific tags, not latest)
  • Persistent storage with volumes
  • Container networking and port management
  • Container lifecycle and process management
Further reading:

Watch Video