Ubuntu
Docker
Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
Installing Docker
There are four ways of installing docker: - Docker Engine comes bundled with Docker Desktop for Linux. This is the easiest and quickest way to get started. - Set up and install Docker Engine from Docker’s apt repository. - Install it manually and manage upgrades manually. - Use a convenience scripts.
It is recommended to user the first two methods. The third method can be long and error prone. The fourth method is recommended only for testing and development environments.
Installing with Docker Desktop
KVM Virtualization Support
Docker Desktop runs a VM that requires KVM support.
The kvm module should load automatically if the host has virtualization support. To load the module manually, run:
modprobe kvm
Depending on the processor of the host machine, the corresponding module must be loaded: - for intel processors
modprobe kvm_intel
- for amd processors
modprobe kvm_amd
If the above commands fail, you can view the diagnostics by running:
kvm-ok
To check if the KVM modules are enabled, run:
lsmod | grep kvm
Set up KVM device user permissions
To check ownership of /dev/kvm, run :
ls -al /dev/kvm
Add your user to the kvm group in order to access the kvm device:
sudo usermod -aG kvm $USER
Set up the repository
- Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
- Add Docker’s official GPG key:
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- Use the following command to set up the 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
Once the repository has been setup, download the latest DEB Package.
Go the the directory where you downloaded the DEB package. Install it as follows:
sudo apt-get update
sudo apt-get install ./docker-desktop-<version>-<arch>.deb
Docker Desktop has been installed. Open it from your applications.
Alternatively, open it from termonal with:
systemctl --user start docker-desktop
Installing with apt repository
Set up the repository
This is the same step as we do in installing docker desktop.
Install Docker Engine
sudo apt-get update
If you get a GPG error, granting read permission for the Docker public key file before updating the package index:
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt-get update
Run the following command on terminal:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify that the Docker Engine installation is successful by running the hello-world image:
sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
Install manually
- Go to https://download.docker.com/linux/ubuntu/dists/.
- Select your Ubuntu version in the list.
- Go to pool/stable/ and select the applicable architecture (amd64, armhf, arm64, or s390x).
- Download the following deb files for the Docker Engine, CLI, containerd, and Docker Compose packages:
- containerd.io_
_ .deb - docker-ce_
_ .deb - docker-ce-cli_
_ .deb - docker-buildx-plugin_
_ .deb - docker-compose-plugin_
_ .deb - Install the .deb packages. Update the paths in the following example to where you downloaded the Docker packages.
sudo dpkg -i ./containerd.io_<version>_<arch>.deb \
./docker-ce_<version>_<arch>.deb \
./docker-ce-cli_<version>_<arch>.deb \
./docker-buildx-plugin_<version>_<arch>.deb \
./docker-compose-plugin_<version>_<arch>.deb
The Docker daemon starts automatically. 6. Verify that the Docker Engine installation is successful by running the hello-world image:
sudo service docker start
sudo docker run hello-world