Installing and Configuring Docker on Linux
Installing Docker on Ubuntu 22.04
- Update the package index:
sudo apt-get update
- Install the necessary packages to allow
apt
to use a repository over HTTPS:
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
- Add the official Docker GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- Set up the Docker repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Install Docker Engine, containerd, and Docker Compose:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Configuring Docker
- Verify the Docker installation:
sudo docker run hello-world
- Add your user to the Docker group to run Docker commands without
sudo
:
sudo usermod -aG docker $USER
- Configure Docker to start automatically on system boot:
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
- (Optional) Configure Docker to use a different storage driver:
sudo vi /etc/docker/daemon.json
Add the following configuration and save the file:
{
"storage-driver": "overlay2"
}
- Restart the Docker service:
sudo systemctl restart docker
Docker Compose Installation
- Download the latest version of Docker Compose:
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
- Make the binary executable:
sudo chmod +x /usr/local/bin/docker-compose
- Verify the Docker Compose installation:
docker-compose --version