Install, experience and uninstall Docker in Centos system

Table of contents

1. Automatic installation

2. Manual installation

Uninstall old version

Set up Yum repository

Install Docker Engine-Community (Community Edition)

3. Docker verification

Check Docker version

Print Docker installation details

Run hello-world image

View hello-world mirror

Start, stop and check status

Set up startup

Configure image accelerator

4. Docker experience

Pull the latest Nginx image

View image

Run container

Access container applications

5. Docker uninstallation

Stop all running containers

Delete all containers

Delete all images

Remove installation package 

Delete Docker data directory


1. Automatic installation

Use the official script to automatically install it with one click. Because the default foreign mirror warehouse download is slow, --mirror Aliyun means to set the mirror warehouse to the domestic Alibaba Cloud.

# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

# Executing docker install script, commit: e5543d473431b782227f8908005543bb4389b8de
+ sh -c 'yum install -y -q yum-utils'
+ sh -c 'yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo'
...
+ sh -c 'yum install -y -q docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin'
...

2. Manual installation

Uninstall old version

[root@node2 ~]# yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

Set up Yum repository

First, install the following software packages. Among them, yum-utils is a collection of tool packages of yum. It provides the yum-config-manager command for managing software warehouses. The device mapper (physical block device is mapped to a logical block) storage driver is required. Install device-mapper-persistent-data (manage and persist device mapper configuration information) and lvm2 (disk partition management).

[root@node2 ~]# sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

Next, set the yum warehouse address. Alibaba Cloud is selected here. By default, the download speed from foreign sources is relatively slow.

[root@node2 ~]# yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Install Docker Engine-Community (Community Edition)

# yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

3. Docker verification

Check Docker version

[root@node2 ~]# docker -v
Docker version 24.0.6, build ed223bc

Print Docker installation details

[root@node2 ~]# docker info
Client: Docker Engine - Community
 Version:    24.0.6
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.21.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info

Server reported an error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. The reason is that Docker does not start by default after installation. Execute the startup command:

systemctl start docker

 Print Docker installation details again

[root@node2 ~]# docker info
Client: Docker Engine - Community
 Version:    24.0.6
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.21.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 24.0.6
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
 runc version: v1.1.9-0-gccaecfc
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-1160.95.1.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 38.83GiB
 Name: node2
 ID: 15c82aef-8778-4ccc-9a65-8f7a66798090
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Run hello-world image

By default, the hello-world image is searched locally first, and if it cannot be found, it is pulled from the remote warehouse.

[root@node2 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete 
Digest: sha256:4f53e2564790c8e7856ec08e384732aa38dc43c52f02952483e3f003afbf23db
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

View hello-world mirror

[root@node2 ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    9c7a54a9a43c   4 months ago   13.3kB

Start, stop and check status

systemctl start|stop|status docker

Set up startup

systemctl enable docker

Configure image accelerator

Due to network problems in foreign countries, it is generally slow to pull images. You can set up a domestic image warehouse. Here we take Alibaba Cloud as an example. The address is:Alibaba Cloud Login - Welcome to Alibaba Cloud , a safe and stable cloud computing service platform.

Configure Alibaba Cloud accelerator according to the documentation:

[root@node2 ~]# cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://sy20zqmi.mirror.aliyuncs.com"]
}
> EOF

 Reload and restart

[root@node2 ~]# systemctl daemon-reload
[root@node2 ~]# systemctl restart docker

4. Docker experience

Pull the latest Nginx image

[root@node3 ~]# docker pull nginx:latest

View image

[root@node2 ~]# docker images
REPOSITORY   TAG                IMAGE ID       CREATED         SIZE
nginx        latest             605c77e624dd   21 months ago   141MB

Run container

Start a container using docker run

[root@node3 ~]# docker run \
--name my-nginx \
-p 8080:80 \
-v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v ~/nginx/logs:/var/log/nginx \
-v ~/nginx/html:/usr/share/nginx/html \
-d nginx
5fc0a603a87cfb3377cf4c54a0d6763e96646a33a3b3e20956be7cb2f6721697

--name means giving the container a name.

-p Host port: Container port, which means publishing the container port to the host. Simply put, it maps the host port and the container port. Here, the nginx container port 80 is mapped to the host port 8080. Remember the order. reverse.

-v host directory: container directory, which means that the host directory is bound and mounted to the container directory, which can persist the container directory data. The data in the container and host directories are synchronized in real time and in both directions. Simply put, between the host and Data sharing between containers. Docker supports mounting multiple directories by specifying multiple -v.

-d means to run the container in the background and print the container id.​ 

Access container applications

Enter the host IP:port in the browser to access the nginx homepage. This machine ishttp://192.168.5.12:8080/

5. Docker uninstallation

Stop all running containers

[root@node2 ~]# docker stop $(docker ps -aq)

Delete all containers

[root@node2 ~]# docker rm $(docker ps -aq)

Delete all images

[root@node2 ~]# docker rmi $(docker images -q)

Remove installation package 

[root@node2 ~]# yum remove -y docker-ce docker-ce-cli containerd.io

Delete Docker data directory

Delete images, containers, configuration files, etc.

rm -rf /var/lib/docker

Supongo que te gusta

Origin blog.csdn.net/BlogPan/article/details/133439516
Recomendado
Clasificación