Install Docker on Ubuntu
Install Docker on Ubuntu
- Enviroment: Ubuntu=24.4
Firewall limitations
If using
ufworfirewalldto manage firewall settings,When you expose container ports using Docker, these ports bypass your firewall rules.
Docker is only compatible with
iptables-nftandiptables-legacy.Firewall rules created with
nftare not supported on a system with Docker installed.
Make sure that any firewall rulesets you use are created withiptablesorip6tables, and that you add them to the DOCKER-USER chain.
Uninstall Docker(old versions)
Uninstall the Docker Engine, CLI, containerd, and Docker Compose packages:
1
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extrasRemove all images, containers, and volumes:
1
2sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerdRemove source list and keyrings
1
2sudo rm /etc/apt/sources.list.d/docker.list
sudo rm /etc/apt/keyrings/docker.asc
Installation
Switch apt sources
Backup source list
1
sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bakFind out sources
Here I use Tsinghua mirrorModify the source
1
sudo vi /etc/apt/sources.list.d/ubuntu.sourcesUpdate
1
2sudo apt-get update
sudo apt-get upgrade
Install using the apt repository
Set up the Docker apt repository
1
2
3
4
5
6
7
8
9
10
11
12# Add Docker's official GPG key:
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get updateInstall the Docker packages
1
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginVerify that the installation is successful
Check docker command:
1
2sudo docker image ls
# REPOSITORY TAG IMAGE ID CREATED SIZEOR running the hello-world image:
1
sudo docker run hello-worldThe later one may issue error for two reason:
Run without
sudo: The docker user group exists but contains no users, which is why you’re required to use sudo to run Docker commands.Can not access to Docker Hub: The image ‘hello-world’ is not exist locally, it requires to get access to Docker Hub to download the image.
Reference
https://docs.docker.com/engine/install/ubuntu/
https://www.cnblogs.com/lcxhk/p/14951334.html