How to Install Docker and Docker Compose on CentOS 8
Docker is a powerful platform for managing and running containers — lightweight, portable environments that package together everything needed to run an application, including the operating system, libraries, and dependencies. Within a Docker container, a minimal Linux distribution and all required software components are bundled into a self-contained unit. Once built, this container can be easily moved and executed on any system where Docker is installed, regardless of the underlying host OS. This ensures consistent behavior across development, testing, and production environments — one of the key reasons why Docker has become an essential tool for developers, system administrators, and DevOps engineers alike. Its portability, scalability, and efficiency have made it the go-to solution for modern software delivery workflows.
In the Serverspace you can create a server with already installed app "Docker".
In this step-by-step tutorial, we will walk through the process of installing Docker and Docker Compose on a CentOS 8 system. After the installation, we’ll also verify that everything is working correctly by running a test container to ensure your environment is ready for containerized applications.
Docker installation on CentOS 8
To install and always update Docker to the latest version, add the developer repository to the system.
Install the Docker package.
Start the Docker service and add it to autorun.
CentOS 8 uses a firewall other than Docker. Hence, if you have firewalld enabled, you need to add a masquerade rule to it.
firewall-cmd --reload
Docker compose installation
Docker is often installed along with Docker compose. It is this utility that allows you to deploy your project to another machine using one command. To download it, run the following command:
Make it executable.
Using Docker as a non-root user
To be able to use Docker as a non-root user, you must add that user to the docker group.
Replace the username with the desired user name. After executing this command, he will need to log out from the system and log in again.
Be careful! Users of this group can take control of the Docker host.
Docker test container running
You can verify that Docker is working properly by running a test container.
As a result of executing the command, you should see a message that everything is working well.
FAQ: Installing Docker and Docker Compose on CentOS 8
- Q: What’s the difference between Docker and Docker Compose?
A: Docker allows you to run individual containers, while Docker Compose lets you define and run multi-container applications using a single YAML file. It’s especially useful for managing complex setups with databases, backends, and frontends. - Q: Do I always need root access to use Docker?
A: No, you can configure Docker to work without root by adding your user to the docker group. However, be cautious: users in this group effectively have root-level access to the system. - Q: Why do I need to enable masquerading in the firewall?
A: On CentOS 8, Docker’s networking may not work correctly with firewalld unless IP masquerading is enabled. This allows Docker containers to access external networks. - Q: How do I check the Docker and Docker Compose versions?
A: Run docker --version and docker-compose --version to verify installed versions and ensure everything was installed correctly. - Q: Is it safe to use the latest version of Docker from the developer repository?
A: Yes, adding Docker’s official repository ensures you're installing the most stable and secure release directly from Docker Inc., with regular updates. - Q: Can I install Docker automatically on my virtual server?
A: Yes! If you're using Serverspace, you can deploy a virtual server with Docker preinstalled via the control panel.