A prerequisite for
- System requirements
To install the Docker engine, you need maintenance versions of CentOS 7 or 8. Archived versions are not supported or tested. The repository must be enabled. By default, this repository is enabled, but if it has been disabled, you need to re-enable it. Centos-extras recommends using a storage driver. overlay2
- Uninstall the previous version
Older versions of Docker are called or. If these components are installed, uninstall them and their associated dependencies. dockerdocker-engine
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
Copy the code
Installation method
- Most users set up Docker repositories and install these repositories to facilitate installation and upgrade tasks. This is the recommended method.
- Some users download the RPM package and install it manually, and manage the upgrade completely manually. This is very useful when installing Docker on a void-based system without Internet access.
- In test and development environments, some users choose to install Docker using automatic convenience scripts.
Using the repository
Before you install the Docker engine for the first time, you need to set up the Docker repository. After that, Docker can be installed and updated from the repository.
- Setting up the repository
Install packages (providing utilities) and set up stable repositories. yum-utilsyum-config-manager
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
Copy the code
Install the Docker
- Install the latest version of the Docker engine and container, or go to the next step to install a specific version:
$ sudo yum install docker-ce docker-ce-cli containerd.io
Copy the code
- To install a specific version of the Docker engine, list the available versions in the repository, then select and install:
1. List and sort the versions available in the repository. This example sorts the results by version number, from highest to lowest, and truncates:
$docker yum list - ce - showduplicates | sort - r docker - ce. X86_64 3:20. 10.2-3. El7 docker - ce - stable docker - ce. X86_64 X86_64 3:20.10.0-3.el7 docker-ce-stable docker-ce. X86_64 3:19.03.9-3.el7 docker-ce-stable docker-ce X86_64 3:19.03.8-3.el7 docker-ce-stable Docker-ce. X86_64 3:19.03.7-3.el7 docker-ce-stable X86_64 3:19.03.6-3.el7 docker-ce-stable docker-ce. X86_64 3:19.03.5-3.el7 docker-ce-stable docker-ce. X86_64 3:19.03.5-3.el7 docker-ce-stable docker-ce X86_64 3:19.03.3-3.el7 docker-ce-stable docker-ce. X86_64 3:19.03.3-3.el7 Docker-ce-stable docker-ce. X86_64 3:19.03.2-3.el7 X86_64 3:19.03.14-3.el7 docker-ce-stable docker-ce. X86_64 3:19.03.3-3. el7 docker-ce-stable Docker-CE X86_64 3:19.03.12-3.el7 docker-ce-stable docker-ce. X86_64 3:19.03.12-3.el7 docker-ce-stable docker-ce 3. 03.11-3. El7 docker - ce - stable... .Copy the code
2. Install the specific version with the fully qualified package name, that is, the package name () plus the version string (column 2), starting with the first colon () and, initially, a hyphen, separated by a hyphen (). For example,. The docker – ce: – docker – ce – 18.09.1
$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
Copy the code
3. Start the Docker
$ sudo systemctl start docker
Copy the code
4. Verify the Docker engine installation by running the image. hello-world
$ sudo docker run hello-world
Copy the code
Uninstall the Docker
1. Uninstall the Docker engine, CLI, and container package.
$ sudo yum remove docker-ce docker-ce-cli containerd.io
Copy the code
2. Images, containers, volumes, and custom configuration files on the host are not automatically deleted. To delete all images, containers, and volumes:
$ sudo rm -rf /var/lib/docker
Copy the code
The above is from official documentation
Docker delete images and containers
- Remove the mirror
Sudo docker rmICopy the code
- Remove the container
Sudo docker rmI < container id or name >Copy the code
CentOS7 field
- Install the latest version
sudo yum install -y docker-ce docker-ce-cli containerd.io
Copy the code
Check the version
# docker version
Client: Docker Engine - Community
Version: 20.10.2
API version: 1.41
Go version: go1.13.15
Git commit: 2291f61
Built: Mon Dec 28 16:17:48 2020
OS/Arch: linux/amd64
Context: default
Experimental: true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Copy the code
Start, status, stop operations
Sudo systemctl status docker docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; Vendor PRESET: disabled) Active: Active (running) since 3 2021-01-06 15:08:56 CST; 12s ago Docs: https://docs.docker.com Main PID: 12965 (dockerd) Tasks: 15 Memory: 49.8m CGroup: / system. Slice/docker. Service └ ─ 12965 / usr/bin/dockerd -h fd: / / -- containerd = / run/containerd containerd. The sock on January 6 15:08:55 localhost.localdomain dockerd[12965]: Time ="2021-01-06T15:08:55.976352192+08:00" level=info MSG =" Scheme \" Unix \" not registered Fallback to default scheme" module= GRPC 1月 06 15:08:55 localhost. Localdomain dockerd[12965]: Time ="2021-01-06T15:08:55.976400676+08:00" level=info MSG ="ccResolverWrapper: Sending update to cc: {[{Unix: / / / run/containerd containerd sock < nil > 0...} "module = GRPC January 6 15:08:55 localhost. Localdomain dockerd [12965] : Time ="2021-01-06T15:08:55.976413942+08:00" level=info MSG ="ClientConn switching balancer to \"pick_first\"" module= GRPC 1月 06 15:08:56 Localhost. Localhost [12965]: Time = "2021-01-06 T15:08:56. 014464634 + 08:00" level = info MSG = "Loading containers: Start." 1月 06 15:08:56 localhost. Localdomain dockerd[12965]: Time ="2021-01-06T15:08:56.376846182+08:00" level=info MSG ="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip... Ed IP address" 1月 06 15:08:56 localhost. Localdomain dockerd[12965]: Time = "2021-01-06 T15:08:56. 449364176 + 08:00" level = info MSG = "Loading containers: Done." 1月 06 15:08:56 localhost. Localdomain dockerd[12965]: Time ="2021-01-06T15:08:56.503601105+08:00" level=info MSG ="Docker daemon" commit= 8891C58 GraphDriver (s)=overlay2 Version =20.10.2 1月 06 15:08:56 Localhost. Localdomain dockerd[12965]: Time ="2021-01-06T15:08:56.503830974+08:00" level=info MSG ="Daemon has completed initialization" 1月 06 15:08:56 localhost.localdomain systemd[1]: Started Docker Application Container Engine. 1月 06 15:08:56 Localhost. Localdomain dockerd[12965]: Time ="2021-01-06T15:08:56.533783267+08:00" level=info MSG ="API listen on /var/run/docker.sock" Hint: Some lines were ellipsized, use -l to show in full. # Stop sudo systemctl stop docker Warning: Stopping docker.service, but it can still be activated by:docker.socketCopy the code
Hello – World
sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Copy the code
Docer image, container
Sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world Sudo Docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e1428020fb1d hello-world "/hello" 17 minutes ago Exited (0) 17 minutes ago inspiring_kirch # CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESCopy the code
Pull the mirror
The search command
docker search [option] keyword
Copy the code
Docker search –help
# docker search --help
Usage: docker search [OPTIONS] TERM
Search the Docker Hub for images
Options:
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print search using a Go template
--limit int Max number of search results (default 25)
--no-trunc Don't truncate output
Copy the code
For example, if we want to search for an official mysql image, run the following command:
# docker search --filter is-official=true mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, The open - source base... 1039 [OK] Mariadb Mariadb is a community-developed fork of MyS... 1039 [OK] Mariadb Mariadb is a community-developed fork of MyS... 3832 [OK] Percona Server is a fork of the MySQL relati... 518 [OK]Copy the code
To view the image version, go to DockerHub to search for mysql keyword and view Tags
- Docker image acceleration
Sometimes it is difficult to pull the image from DockerHub in China, so you can configure the image accelerator. Docker official and many domestic cloud service providers have provided domestic accelerator services, such as: Chinese official: registry.docker-cn.com Alicloud: https://< your ID>.mirror.aliyuncs.com
Ubuntu16.04+, Debian8+, CentOS7, etc/docker/daemon.json (if the file does not exist, please create it) :
{"registry-mirrors":["https://registry.docker-cn.com"]}
Copy the code
Mysql5.7 Mirroring (not configured with mirror acceleration a little slow, but ok)
hub.docker.com/_/mysql
# sudo docker pull mysql:5.7.32 5.7.32: Pulling from library/mysql 6ec7b7d162B2: pull complete fedd960d3481: Pull complete 7ab947313861: Pull complete 64f92f19e638: Pull complete 3e80b17bff96: Pull complete 014e976799f9: Pull complete 59ae84fee1b3: Pull complete 7d1da2a18e2e: Pull complete 301a28b700b9: Pull complete 529dc8dbeaf3: Pull complete bc9d021dc13f: Pull complete Digest: sha256:c3a567d3e3ad8b05dfce401ed08f0f6bf3f3b64cc17694979d5f2e5d78e10173 Status: Downloaded newer image for mysql: 5.7.32 docker. IO/library/mysql: 5.7.32Copy the code
Running mysql
Run:
Docker run -d 3306:3306 --name mysql5.7.32 -e MYSQL_ROOT_PASSWORD=123456 mysql5.7.32 Settings must be Mysql parameter docker run - d - 3306 p: 3306 - name mysql5.7.32 \ v/home/dockermysql/conf: / etc/Mysql \ - v /home/dockermysql/logs:/var/log/mysql \ -v /home/dockermysql/data:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=123456 \ Mysql5.7.32 \ --lower_case_table_names=1 \ --max-allowed-packet=1073741824 \ -- Character_set_server = UTf8 \ --innodb_log_file_size=256m 2f63f45453b31fcb61a2708643e77575fb734ad2234084502b46dbf4249fa638Copy the code
Command description: –name mysql5.7.32: create the container name -p 3306:3306: map port 3306 of the container to port 3306 of the host -v / home/dockermysql/conf: / etc/mysql: the host/home/dockermysql/conf directory mounted to the container/etc/mysql… Mysql :5.7.32: MYSQL_ROOT_PASSWORD=123456: mysql:5.7.32: MYSQL_ROOT_PASSWORD=123456 –lower_case_table_names=1: set the table name and other parameters to ignore case. –max-allowed-packet=1073741824: Set the maximum insert and update data limit to 1 GB. Unit: Byte — CHARACTER_set_server = UTF8: set UTF8 character set –innodb_log_file_size=256m: set log size
To view:
# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES AE1e7049425b mysql:5.7.32 "docker-entryPoint.s..." 54 seconds ago Up 53 seconds 0.0.0.0:3306->3306/ TCP, 33060/ TCP mysql5.7.32Copy the code