Technology Sharing

Introduction to Docker and its use

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

The company uses Docker, and every team member uses it silently without any explanation or training. It's really funny.

Table of contents

1. Docker Installation

You need to use a ladder to access the docker official website:Install Docker Engine on Ubuntu

Here is a question: What is the relationship between Docker Engine, Docker, and DockerDesktop?

The page, under "Install Docker Engine on Ubuntu", "Installation methods" describes:
You can install Docker Engine in different ways, depending on your needs
1)Docker Engine comes bundled with Docker Desktop for Linux. This is the easiest and quickest way to get started.
Docker Engine comes bundled with Docker Desktop for Linux. This is the easiest and quickest way to get started
2)Set up and install Docker Engine from Docker’s apt repository.
Setup and install Docker engine using Docker’s apt repository.
3)Install it manually and manage upgrades manually.
Install it manually and manage upgrades manually.
4)Use a convenience script. Only recommended for testing and development environments.
Use a convenience script. Recommended only for testing and development environments.

Following the instructions above, installing Docker Desktop is the simplest way, but after downloading Docker Desktop.deb, the installation fails with the following prompt:
sudo apt-get update
sudo apt-get install ./docker-desktop-amd64.deb

The following packages have unmet dependencies:
docker-desktop : Depends: docker-ce-cli but it is not installable
E: Unable to correct problems, you have held broken packages.

Official website documentation,
insert image description here
I originally thought that the version of ubuntu20 was wrong, but I couldn’t find a version suitable for ubuntu20. I am a little confused here?

Search QuestionsUnable to install Docker Desktop on Ubuntu 22.04

Docker Desktop has a dependency on the docker CLI, which requires the download.docker.com package repository to be set up before installing the docker-desktop package; from the error message, I suspect you didn’t set up that repository (see “step 1” in the instructions; https://docs.docker.com/desktop/install/ubuntu/#install-docker-desktop
(Docker Desktop depends on the docker CLI, which requires the download.docker.com package repository to be set up before installing the docker-desktop package; from the error message I suspect you don't have that repository set up (see "Step 1" in the instructions; https://docs.docker.com/desktop/install/ubuntu/#install-docker-desktop)

Combined with the document:Installing Docker Desktop on Ubuntu

Then in the Docker documentation Desktop download pageInstall Docker Desktop on Ubuntu

Install Docker Desktop
Recommended approach to install Docker Desktop on Ubuntu:
1.Set up Docker’s package repository. See step one of Install using the apt repository.
2.Download latest DEB package.
3.Install the package with apt as follows:
sudo apt-get update
sudo apt-get install ./docker-desktop-<arch>.deb

You need to install Docker's package repository first. I don't know what it has to do with Docker or what it is used for.

Install using the apt repository
Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
1.Set up Docker’s apt repository.

# Add Docker's official GPG key:
sudo apt-get update
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 update
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

2.Install the Docker packages.
Latest:

To install the latest version, run:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  • 1
  • 2

Specific version:

To install a specific version of Docker Engine, start by listing the available versions in the repository:
# List the available versions:
apt-cache madison docker-ce | awk '{ print $3 }'

5:27.0.3-1~ubuntu.24.04~noble
5:27.0.2-1~ubuntu.24.04~noble
...
Select the desired version and install:
VERSION_STRING=5:27.0.3-1~ubuntu.24.04~noble
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

3.Verify that the Docker Engine installation is successful by running the hello-world image.

sudo docker run hello-world
  • 1

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

You need to use sudo to run Docker commands

question:
Command sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc Stuck? ! !
Solution:Installing Docker in Ubuntu, adding Docker official GPG key failed, solution
(1) First download the official GPG key to your local computer. The downloaded file is a gpg file.
(2) After downloading to the local computer, use the following command to install the official GPG key:

sudo apt-key add ./gpg

The Linux apt-key mechanism needs further study

After using the local sudo apt-key add ./gpg gpg command, I think the Add the repository to Apt sources command to add the docker library should be modified, but I don't know how to modify it

I used the downloaded Desktop.deb file

There is a problem. There is a problem. . . .