How to Install Docker Images on Linux


Installing Docker images on Linux sounds like you are putting a tiny app into a tiny box and telling it to behave. That is surprisingly close to the truth. A Docker image is a packaged, portable snapshot of an application and everything it needs to run: code, runtime, libraries, tools, and default settings. Instead of spending an afternoon arguing with dependencies, you can pull an image, run a container, and get back to the important worklike pretending your terminal errors are “learning opportunities.”

Before we go further, here is the most important distinction: you do not technically “install” Docker images the same way you install normal Linux packages. You install Docker Engine on Linux, then you pull Docker images from a registry such as Docker Hub, GitHub Container Registry, or a private registry. After that, you run those images as containers.

This guide walks through the complete process: installing Docker on Linux, downloading Docker images, running containers, managing image versions, cleaning up unused images, and avoiding beginner mistakes. Whether you are using Ubuntu, Debian, Fedora, Rocky Linux, or another modern Linux distribution, the concepts are nearly the same.

What Is a Docker Image?

A Docker image is a read-only template used to create containers. Think of it like a cake recipe plus the ingredients already measured out. The container is the cake actually baking in your oven. One image can create one container, ten containers, or an army of containers if your server has enough resources and your coffee has enough courage.

For example, the official nginx image includes the Nginx web server and its required environment. The mysql image includes MySQL. The ubuntu image gives you a minimal Ubuntu environment. These images live in registries, and Docker downloads them to your local Linux machine when you run docker pull or docker run.

Prerequisites Before Installing Docker Images on Linux

Before pulling your first Docker image, make sure your Linux system is ready. You need a 64-bit Linux distribution, access to a user account with sudo privileges, a working internet connection, and enough disk space for container images. Some images are tiny, like Alpine Linux. Others are chunky enough to make your storage sigh dramatically.

Docker Engine is commonly installed from Docker’s official package repositories. This is usually better than relying on older distro-provided packages because the official repository receives current Docker Engine, Docker CLI, containerd, Buildx, and Docker Compose plugin packages.

Step 1: Remove Conflicting Docker Packages

If your system already has older or unofficial Docker packages, remove them first. On Ubuntu or Debian, use:

Do not panic if your terminal says some packages are not installed. That is normal. Linux is simply telling you, “I checked the closet; nothing scary in there.”

Step 2: Install Docker Engine on Ubuntu or Debian

Ubuntu and Debian use the apt package manager. The recommended method is to add Docker’s official GPG key, set up the Docker repository, update the package index, and install Docker Engine.

Install required packages

Add Docker’s official GPG key

For Debian, replace the Ubuntu URL path with:

Add the Docker repository

For Ubuntu, run:

For Debian, use:

Install Docker packages

Step 3: Install Docker Engine on Fedora

Fedora uses dnf. To install Docker Engine on Fedora, first set up the repository:

Then install Docker:

Start and enable Docker:

Step 4: Verify That Docker Works

Once Docker Engine is installed, confirm that the service is running:

Then run the classic test container:

If everything is working, Docker will pull the hello-world image, create a container from it, run it, and print a confirmation message. It is the Docker equivalent of a handshake, except the handshake includes layers, registries, and fewer awkward conference badges.

Step 5: Run Docker Without Typing sudo Every Time

By default, Docker commands usually require root privileges. If you want to run Docker as your normal user, add your user to the docker group:

Then test:

Important security note: membership in the docker group grants powerful privileges. On a personal development machine, this is common. On a production server, be more careful. For stronger isolation, consider Docker rootless mode, which allows the Docker daemon and containers to run without full root privileges.

Step 6: Pull a Docker Image on Linux

Now for the main event: installing Docker images on Linux. The basic command is:

For example, to download the latest Nginx image:

To pull a specific version, use a tag:

If you do not specify a tag, Docker defaults to latest. However, latest does not always mean newest in the way people expect. It means the image publisher assigned the latest tag to that version. For predictable deployments, use a specific version tag or digest.

Step 7: Run a Docker Image as a Container

Pulling an image downloads it. Running an image creates a container. For example:

This starts an Nginx container in the foreground. For a more practical web server example, run it in detached mode and publish port 80 from the container to port 8080 on your Linux host:

Now open your browser and visit:

You should see the Nginx welcome page. Congratulations: you just ran a web server without manually installing Nginx on your host system. Your Linux machine remains cleaner, and your future self may send you a thank-you card.

Step 8: List Docker Images

To see images downloaded to your system, run:

You will see columns such as repository, tag, image ID, creation date, and size. This helps you understand what is stored locally and whether your disk is quietly filling up with old experiments named “test-final-final-real-final.”

Step 9: List Running Containers

To view active containers:

To view all containers, including stopped ones:

This is useful because images and containers are different. Removing a container does not automatically remove the image. Removing an image does not necessarily remove a running container. Docker is organized, but it expects you to be organized too. Rude, but fair.

Step 10: Stop and Remove Containers

To stop a running container:

To remove it:

If you want to run a short-lived container that removes itself after exiting, use --rm:

Step 11: Remove Docker Images

To remove an image from your Linux machine, use:

Example:

If the image is used by an existing container, Docker may refuse to remove it until the container is deleted. This is not Docker being stubborn; it is Docker preventing you from yanking the floor out from under a container that still depends on that image.

Step 12: Clean Up Unused Docker Images

Over time, Docker can accumulate unused images, stopped containers, unused networks, and build cache. To remove dangling images, run:

To remove all unused images, not just dangling ones:

To clean stopped containers, unused networks, dangling images, and build cache in one command:

Be careful with cleanup commands, especially on shared servers. A dramatic cleanup can feel satisfying until someone asks where the staging environment went.

How to Pull Images from Docker Hub

Docker Hub is the default public registry for Docker images. If you run:

Docker pulls the Redis image from Docker Hub. Official images, such as ubuntu, nginx, mysql, postgres, redis, and node, are popular because they are maintained with broad community and publisher support.

You can also pull images from a specific namespace:

Example:

How to Pull Images from GitHub Container Registry

GitHub Container Registry uses the ghcr.io domain. A public image can often be pulled anonymously:

For private images, you need to log in:

Then pull the image:

Tags vs. Digests: Which Should You Use?

Tags are human-friendly labels, such as ubuntu:24.04 or nginx:1.27. Digests are cryptographic identifiers that point to exact image content. Tags can be updated by publishers, but digests are immutable. For everyday development, tags are convenient. For production deployments, pinned versions or digests provide better consistency.

Example with a tag:

Example with a digest:

Using digests may look less friendly, but production systems prefer boring predictability. Boring servers are usually happy servers.

Building Your Own Docker Image on Linux

Sometimes you do not want to pull someone else’s image. You want to build your own. Create a file named Dockerfile:

Then build the image:

Run it:

When building images, keep them small, use trusted base images, avoid unnecessary packages, and pin important versions. A lean image downloads faster, starts faster, and provides a smaller attack surface.

Common Docker Image Installation Problems on Linux

Permission denied while connecting to Docker

If you see a permission error, either use sudo or add your user to the Docker group. After changing groups, log out and back in, or run newgrp docker.

Image not found

Check the image name, namespace, registry, and tag. For example, nginx and library/nginx refer to the official image on Docker Hub, but private images require the correct registry path.

No space left on device

Run docker system df to inspect Docker disk usage. Then remove stopped containers and unused images carefully. Your disk did not betray you; it just got buried under six months of “quick tests.”

Container exits immediately

Some images run a command and stop when that command finishes. Use docker logs container_name to inspect output. For interactive images, run:

Docker Image Security Best Practices

Installing Docker images is easy. Installing safe Docker images requires attention. Use official or verified images when possible. Read image documentation before running it. Avoid random images from unknown publishers, especially if they require privileged mode or host mounts.

Scan images for vulnerabilities when your workflow supports it. Keep base images updated. Do not run containers as root unless necessary. Avoid storing secrets directly inside images. Use environment variables, secret managers, or orchestrator-level secret tools instead.

For production, choose specific tags or digests, review Dockerfiles, and rebuild images regularly. Containers are portable, but vulnerabilities are portable too. That is not the kind of portability anyone asked for.

Practical Examples of Installing Docker Images on Linux

Install and run PostgreSQL

Install and run Redis

Install and run Ubuntu interactively

Install and run Node.js

Real-World Experience: What You Learn After Installing Docker Images on Linux for a While

The first real lesson is that Docker feels magical until you forget what is running. In the beginning, you pull an image, run a container, and feel like you have unlocked a developer superpower. Then, three weeks later, you type docker ps -a and discover a small museum of abandoned containers. Some are named automatically, like sleepy_turing or bold_penguin, which makes the mess sound much more charming than it really is.

A good habit is to name important containers with --name. Instead of letting Docker invent a name, use something obvious like dev-postgres, local-redis, or nginx-test. Your future self will instantly know what each container does. This is especially helpful when you are running multiple databases, message queues, and web servers on the same Linux machine.

The second lesson is that tags matter. Pulling latest is fine for quick experiments, but it can surprise you later. An image tagged latest may change, and your project may behave differently after a fresh pull. When working on tutorials, production services, or team projects, use versioned tags such as postgres:16, redis:7, or ubuntu:24.04. It makes debugging less mysterious. Mystery is great in detective novels, not in deployment logs.

The third lesson is to treat storage as a real resource. Docker images use layers, which is efficient, but disk usage still grows. Build cache, old images, and stopped containers can pile up quickly. Run docker system df occasionally to see what Docker is using. Then prune carefully. Do not blindly run aggressive cleanup commands on a production server unless you know what they will remove.

The fourth lesson is that logs are your best friend. When a container exits immediately or refuses to behave, run docker logs container_name. Many beginners rebuild images, reinstall Docker, or restart the whole machine before checking logs. That is like replacing your car engine before reading the dashboard warning light.

The fifth lesson is that Docker is most powerful when paired with simple documentation. Keep a short README for your project with the exact docker pull, docker run, port mapping, volume, and environment variable commands. This saves time when moving between machines or helping teammates. A clean command copied from documentation beats a heroic memory every time.

Finally, remember that Docker images are tools, not magic shields. A container can isolate an application, but it does not automatically make insecure software secure. Use trusted images, keep them updated, limit privileges, and understand what ports and volumes you expose. Once these habits become natural, installing Docker images on Linux becomes fast, repeatable, and refreshingly boringthe good kind of boring, where things just work.

Conclusion

Installing Docker images on Linux is really a two-part process: first, install Docker Engine; second, pull and run the images you need. Once Docker is ready, commands like docker pull nginx, docker run -d -p 8080:80 nginx, and docker image ls become part of your everyday toolkit.

The best approach is simple: install Docker from the official repository, use trusted images, choose specific tags, understand the difference between images and containers, and clean up unused resources regularly. Docker gives Linux users a flexible way to test applications, run services, build development environments, and deploy software with fewer dependency headaches. It is not magic, but on a busy day, it can feel close.