Step-by-Step Guide
- Update the Package Index
Open a terminal and update the package index to ensure you have the latest information about available packages:
sudo yum update -y
- Install Required Packages
Install the required packages for Docker:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- Add Docker Repository
Add the Docker repository to your system:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- Install Docker
Install Docker using theyum
package manager:
sudo yum install -y docker-ce docker-ce-cli containerd.io
- Start and Enable Docker
Start the Docker service:
sudo systemctl start docker
Enable Docker to start on boot:
sudo systemctl enable docker
- Verify Docker Installation
Check the Docker version to ensure it is installed correctly:
docker --version
You should see the Docker version information displayed.
- Add Your User to the Docker Group (Optional)
To run Docker commands withoutsudo
, add your user to the Docker group:
sudo usermod -aG docker $USER
Log out and log back in for the changes to take effect, or use the following command to apply the changes immediately:
newgrp docker
- Test Docker Installation
To test Docker, run thehello-world
container:
docker run hello-world
If Docker is installed correctly, you should see a message saying “Hello from Docker!”
- Install Docker Compose (Optional)
Docker Compose is a tool for defining and running multi-container Docker applications. To install Docker Compose, download the binary:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
Verify the installation:
docker-compose --version
- Enable Docker at Boot
Ensure Docker starts at boot:bash sudo systemctl enable docker