Docker is a platform that lets you run applications in isolated containers, without needing a full virtual machine. This article shows how to install Docker on a Linux server, how to start your first container, and how to manage containers. After completing the steps, you’ll have a working Docker environment and understand the key commands.
What is Docker and why use it
Docker packages an application together with all required libraries and settings into a container. That container runs identically everywhere, whether you’re testing on your own laptop or deploying to a production server. This prevents the well-known “it works on my machine” problem.
Containers share the operating system’s kernel, making them much lighter than virtual machines. You can run dozens of containers on a single server without each container carrying its own operating system. This makes Docker excellent for testing software, running microservices, or quickly setting up a database.
Installing Docker on Linux
Installation varies slightly per distribution, but the principle is the same: you add the official Docker repository and then install the Docker package. Below are the steps for an Ubuntu or Debian server.
Update the system
Run sudo apt update && sudo apt upgrade -y to make sure your server is up to date before installing new software.
Install prerequisites
Install the required packages with sudo apt install ca-certificates curl gnupg -y.
Add the Docker repository
Add Docker’s GPG key and repository following the official instructions, so you always install a recent and verified version.
Install Docker Engine
Run sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y. This installs both Docker and the compose plugin.
Verify the installation
Check with sudo docker run hello-world whether everything works. If you see a confirmation message, Docker is running correctly.
sudo usermod -aG docker $USER so you can run Docker commands without using sudo every time. Log in again afterward.Running your first container
You start a container with the docker run command, followed by the name of an image. An image is the blueprint from which a container is created. For example:
docker run -d -p 8080:80 --name mijnwebsite nginx
This command pulls the nginx image, starts a container in the background (-d), and maps port 8080 on the server to port 80 inside the container. Open your browser to the server’s IP address on port 8080, and you’ll see the default nginx page.
Images are pulled from Docker Hub, but you can also build your own image with a Dockerfile. In it, you describe step by step how the container should be built, such as which software is installed and which files are copied.
Managing containers
Once your containers are running, you’ll want to view, stop, and clean them up. The key commands are:
docker psshows all running containers.docker ps -aalso shows stopped containers.docker stop [name]stops a container cleanly.docker rm [name]removes a stopped container.docker imagesshows all locally stored images.docker logs [name]shows a container’s log lines, useful for troubleshooting.
To run multiple related containers, such as a web server with a database, use docker-compose. With it, you describe in one file which containers together form an application, and start everything with a single command.
If you run containers on your own server or VPS, make sure you have enough disk space: images and logs can grow quite large. A server with fast NVMe storage prevents this from becoming a bottleneck. If you’d rather not manage your own server for web applications, regular web hosting is often a simpler alternative without having to maintain containers yourself.
Frequently Asked Questions
Can I use Docker on shared hosting?
No, Docker requires full control over the server, such as a VPS or dedicated server. On shared hosting you don’t have root access to install Docker.
What’s the difference between an image and a container?
An image is an immutable blueprint. A container is a running instance of that blueprint, with its own file system and processes.
Do I need to use sudo for every Docker command?
Not necessarily. If your user has been added to the docker group, you can run commands without sudo.
How do I stop all running containers at once?
Use docker stop $(docker ps -q). This stops every container currently running.
Where can I find more technical background articles?
The knowledge base contains more practical guides on server management and hosting.
Conclusion
Installing Docker on Linux takes just a few steps: add the repository, install Docker Engine, and start your first container. With commands like docker run, docker ps, and docker stop, you can easily manage containers. For serious workloads, sufficient disk space and a stable server are important.