前言

提示:CentOS Linux 8的yum源配置
本人Linux镜像为CentOS 8所以需要配置yum源,其他版本可省略
yum源配置

一、Docker安装

1、安装gcc

yum -y install gcc
yum -y install gcc-c++

详细安装如下

[root@localhost yum.repos.d]# yum -y install gcc
Last metadata expiration check: 0:01:42 ago on Tue 08 Nov 2022 02:41:44 PM CST.
Package gcc-8.5.0-3.el8.x86_64 is already installed.
Dependencies resolved.
================================================================================Package         Architecture   Version                 Repository         Size
================================================================================
Upgrading:cpp             x86_64         8.5.0-4.el8_5           AppStream          10 Mgcc             x86_64         8.5.0-4.el8_5           AppStream          23 Mlibgcc          x86_64         8.5.0-4.el8_5           base               79 klibgomp         x86_64         8.5.0-4.el8_5           base              206 kTransaction Summary
================================================================================
Upgrade  4 PackagesTotal download size: 34 M
Downloading Packages:
(1/4): libgcc-8.5.0-4.el8_5.x86_64.rpm          116 kB/s |  79 kB     00:00
(2/4): libgomp-8.5.0-4.el8_5.x86_64.rpm         162 kB/s | 206 kB     00:01
(3/4): cpp-8.5.0-4.el8_5.x86_64.rpm             236 kB/s |  10 MB     00:45
(4/4): gcc-8.5.0-4.el8_5.x86_64.rpm             245 kB/s |  23 MB     01:38
--------------------------------------------------------------------------------
Total                                           354 kB/s |  34 MB     01:38
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing        :                                                        1/1Upgrading        : cpp-8.5.0-4.el8_5.x86_64                               1/8Running scriptlet: cpp-8.5.0-4.el8_5.x86_64                               1/8Upgrading        : libgomp-8.5.0-4.el8_5.x86_64                           2/8Running scriptlet: libgomp-8.5.0-4.el8_5.x86_64                           2/8Upgrading        : libgcc-8.5.0-4.el8_5.x86_64                            3/8Running scriptlet: libgcc-8.5.0-4.el8_5.x86_64                            3/8Upgrading        : gcc-8.5.0-4.el8_5.x86_64                               4/8Running scriptlet: gcc-8.5.0-4.el8_5.x86_64                               4/8Running scriptlet: gcc-8.5.0-3.el8.x86_64                                 5/8Cleanup          : gcc-8.5.0-3.el8.x86_64                                 5/8Running scriptlet: cpp-8.5.0-3.el8.x86_64                                 6/8Cleanup          : cpp-8.5.0-3.el8.x86_64                                 6/8Cleanup          : libgcc-8.5.0-3.el8.x86_64                              7/8Running scriptlet: libgcc-8.5.0-3.el8.x86_64                              7/8Running scriptlet: libgomp-8.5.0-3.el8.x86_64                             8/8Cleanup          : libgomp-8.5.0-3.el8.x86_64                             8/8Running scriptlet: libgomp-8.5.0-3.el8.x86_64                             8/8Verifying        : libgcc-8.5.0-4.el8_5.x86_64                            1/8Verifying        : libgcc-8.5.0-3.el8.x86_64                              2/8Verifying        : libgomp-8.5.0-4.el8_5.x86_64                           3/8Verifying        : libgomp-8.5.0-3.el8.x86_64                             4/8Verifying        : cpp-8.5.0-4.el8_5.x86_64                               5/8Verifying        : cpp-8.5.0-3.el8.x86_64                                 6/8Verifying        : gcc-8.5.0-4.el8_5.x86_64                               7/8Verifying        : gcc-8.5.0-3.el8.x86_64                                 8/8Upgraded:cpp-8.5.0-4.el8_5.x86_64               gcc-8.5.0-4.el8_5.x86_64libgcc-8.5.0-4.el8_5.x86_64            libgomp-8.5.0-4.el8_5.x86_64Complete!
[root@localhost yum.repos.d]# yum -y install gcc-c++
Last metadata expiration check: 0:06:19 ago on Tue 08 Nov 2022 02:41:44 PM CST.
Dependencies resolved.
================================================================================Package               Architecture Version               Repository       Size
================================================================================
Installing:gcc-c++               x86_64       8.5.0-4.el8_5         AppStream        12 M
Upgrading:libstdc++             x86_64       8.5.0-4.el8_5         base            453 k
Installing dependencies:libstdc++-devel       x86_64       8.5.0-4.el8_5         AppStream       2.0 MTransaction Summary
================================================================================
Install  2 Packages
Upgrade  1 PackageTotal download size: 15 M
Downloading Packages:
(1/3): libstdc++-8.5.0-4.el8_5.x86_64.rpm       168 kB/s | 453 kB     00:02
(2/3): libstdc++-devel-8.5.0-4.el8_5.x86_64.rpm 217 kB/s | 2.0 MB     00:09
(3/3): gcc-c++-8.5.0-4.el8_5.x86_64.rpm         219 kB/s |  12 MB     00:57
--------------------------------------------------------------------------------
Total                                           263 kB/s |  15 MB     00:57
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing        :                                                        1/1Upgrading        : libstdc++-8.5.0-4.el8_5.x86_64                         1/4Running scriptlet: libstdc++-8.5.0-4.el8_5.x86_64                         1/4Installing       : libstdc++-devel-8.5.0-4.el8_5.x86_64                   2/4Installing       : gcc-c++-8.5.0-4.el8_5.x86_64                           3/4Cleanup          : libstdc++-8.5.0-3.el8.x86_64                           4/4Running scriptlet: libstdc++-8.5.0-3.el8.x86_64                           4/4Verifying        : gcc-c++-8.5.0-4.el8_5.x86_64                           1/4Verifying        : libstdc++-devel-8.5.0-4.el8_5.x86_64                   2/4Verifying        : libstdc++-8.5.0-4.el8_5.x86_64                         3/4Verifying        : libstdc++-8.5.0-3.el8.x86_64                           4/4Upgraded:libstdc++-8.5.0-4.el8_5.x86_64
Installed:gcc-c++-8.5.0-4.el8_5.x86_64       libstdc++-devel-8.5.0-4.el8_5.x86_64Complete!

2、安装docker依赖

yum install -y yum-utils
[root@localhost yum.repos.d]#  yum install -y yum-utils
Last metadata expiration check: 0:00:52 ago on Tue 08 Nov 2022 02:41:44 PM CST.
Dependencies resolved.
================================================================================Package            Architecture    Version                 Repository     Size
================================================================================
Installing:yum-utils          noarch          4.0.21-3.el8            base           73 kTransaction Summary
================================================================================
Install  1 PackageTotal download size: 73 k
Installed size: 22 k
Downloading Packages:
yum-utils-4.0.21-3.el8.noarch.rpm               151 kB/s |  73 kB     00:00
--------------------------------------------------------------------------------
Total                                           151 kB/s |  73 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing        :                                                        1/1Installing       : yum-utils-4.0.21-3.el8.noarch                          1/1Running scriptlet: yum-utils-4.0.21-3.el8.noarch                          1/1Verifying        : yum-utils-4.0.21-3.el8.noarch                          1/1Installed:yum-utils-4.0.21-3.el8.noarchComplete!

3、设置镜像仓库

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 yum-config-manager --add-repo http://mirrors.aliyun.com/dockerce/linux/centos/docker-ce.repo
Adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4、安装docker

sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
[root@localhost yum.repos.d]# sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Docker CE Stable - x86_64                                                                                                                                 37 kB/s |  31 kB     00:00
Dependencies resolved.
=========================================================================================================================================================================================Package                                         Architecture                 Version                                                       Repository                              Size
=========================================================================================================================================================================================
Installing:containerd.io                                   x86_64                       1.6.9-3.1.el8                                                 docker-ce-stable                        33 Mdocker-ce                                       x86_64                       3:20.10.21-3.el8                                              docker-ce-stable                        21 Mdocker-ce-cli                                   x86_64                       1:20.10.21-3.el8                                              docker-ce-stable                        30 Mdocker-compose-plugin                           x86_64                       2.12.2-3.el8                                                  docker-ce-stable                        10 M
Installing dependencies:container-selinux                               noarch                       2:2.167.0-1.module_el8.5.0+911+f19012f9                       AppStream                               54 kdocker-ce-rootless-extras                       x86_64                       20.10.21-3.el8                                                docker-ce-stable                       4.6 Mfuse-overlayfs                                  x86_64                       1.7.1-1.module_el8.5.0+890+6b136101                           AppStream                               73 kfuse3                                           x86_64                       3.2.1-12.el8                                                  base                                    50 kfuse3-libs                                      x86_64                       3.2.1-12.el8                                                  base                                    94 klibslirp                                        x86_64                       4.4.0-1.module_el8.5.0+890+6b136101                           AppStream                               70 kslirp4netns                                     x86_64                       1.1.8-1.module_el8.5.0+890+6b136101                           AppStream                               51 k
Installing weak dependencies:docker-scan-plugin                              x86_64                       0.21.0-3.el8                                                  docker-ce-stable                       3.8 M
Enabling module streams:container-tools                                                              rhel8Transaction Summary
=========================================================================================================================================================================================
Install  12 PackagesTotal download size: 103 M
Installed size: 394 M
Is this ok [y/N]: y
Downloading Packages:
(1/12): fuse3-3.2.1-12.el8.x86_64.rpm                                                                                                                     85 kB/s |  50 kB     00:00
(2/12): container-selinux-2.167.0-1.module_el8.5.0+911+f19012f9.noarch.rpm                                                                                88 kB/s |  54 kB     00:00
(3/12): fuse3-libs-3.2.1-12.el8.x86_64.rpm                                                                                                               113 kB/s |  94 kB     00:00
(4/12): fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64.rpm                                                                                    162 kB/s |  73 kB     00:00
(5/12): libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64.rpm                                                                                          131 kB/s |  70 kB     00:00
(6/12): slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64.rpm                                                                                       124 kB/s |  51 kB     00:00
(7/12): docker-ce-20.10.21-3.el8.x86_64.rpm                                                                                                              167 kB/s |  21 MB     02:09
(8/12): docker-ce-rootless-extras-20.10.21-3.el8.x86_64.rpm                                                                                              156 kB/s | 4.6 MB     00:30
(9/12): docker-ce-cli-20.10.21-3.el8.x86_64.rpm                                                                                                          160 kB/s |  30 MB     03:08
(10/12): docker-scan-plugin-0.21.0-3.el8.x86_64.rpm                                                                                                      164 kB/s | 3.8 MB     00:23
(11/12): containerd.io-1.6.9-3.1.el8.x86_64.rpm                                                                                                          158 kB/s |  33 MB     03:33
(12/12): docker-compose-plugin-2.12.2-3.el8.x86_64.rpm                                                                                                   162 kB/s |  10 MB     01:04
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                    466 kB/s | 103 MB     03:45
Docker CE Stable - x86_64                                                                                                                                5.8 kB/s | 1.6 kB     00:00
Importing GPG key 0x621E9F35:Userid     : "Docker Release (CE rpm) <docker@docker.com>"Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35From       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing        :                                                                                                                                                                 1/1Installing       : docker-scan-plugin-0.21.0-3.el8.x86_64                                                                                                                         1/12Running scriptlet: docker-scan-plugin-0.21.0-3.el8.x86_64                                                                                                                         1/12Running scriptlet: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                               2/12Installing       : container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                               2/12Running scriptlet: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                               2/12Installing       : containerd.io-1.6.9-3.1.el8.x86_64                                                                                                                             3/12Running scriptlet: containerd.io-1.6.9-3.1.el8.x86_64                                                                                                                             3/12Installing       : docker-ce-cli-1:20.10.21-3.el8.x86_64                                                                                                                          4/12Running scriptlet: docker-ce-cli-1:20.10.21-3.el8.x86_64                                                                                                                          4/12Installing       : libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64                                                                                                            5/12Installing       : slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64                                                                                                         6/12Installing       : fuse3-libs-3.2.1-12.el8.x86_64                                                                                                                                 7/12Running scriptlet: fuse3-libs-3.2.1-12.el8.x86_64                                                                                                                                 7/12Installing       : fuse3-3.2.1-12.el8.x86_64                                                                                                                                      8/12Installing       : fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64                                                                                                      9/12Running scriptlet: fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64                                                                                                      9/12Installing       : docker-ce-3:20.10.21-3.el8.x86_64                                                                                                                             10/12Running scriptlet: docker-ce-3:20.10.21-3.el8.x86_64                                                                                                                             10/12Installing       : docker-ce-rootless-extras-20.10.21-3.el8.x86_64                                                                                                               11/12Running scriptlet: docker-ce-rootless-extras-20.10.21-3.el8.x86_64                                                                                                               11/12Installing       : docker-compose-plugin-2.12.2-3.el8.x86_64                                                                                                                     12/12Running scriptlet: docker-compose-plugin-2.12.2-3.el8.x86_64                                                                                                                     12/12Running scriptlet: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                              12/12Running scriptlet: docker-compose-plugin-2.12.2-3.el8.x86_64                                                                                                                     12/12Verifying        : fuse3-3.2.1-12.el8.x86_64                                                                                                                                      1/12Verifying        : fuse3-libs-3.2.1-12.el8.x86_64                                                                                                                                 2/12Verifying        : container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                               3/12Verifying        : fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64                                                                                                      4/12Verifying        : libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64                                                                                                            5/12Verifying        : slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64                                                                                                         6/12Verifying        : containerd.io-1.6.9-3.1.el8.x86_64                                                                                                                             7/12Verifying        : docker-ce-3:20.10.21-3.el8.x86_64                                                                                                                              8/12Verifying        : docker-ce-cli-1:20.10.21-3.el8.x86_64                                                                                                                          9/12Verifying        : docker-ce-rootless-extras-20.10.21-3.el8.x86_64                                                                                                               10/12Verifying        : docker-compose-plugin-2.12.2-3.el8.x86_64                                                                                                                     11/12Verifying        : docker-scan-plugin-0.21.0-3.el8.x86_64                                                                                                                        12/12Installed:container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch   containerd.io-1.6.9-3.1.el8.x86_64                          docker-ce-3:20.10.21-3.el8.x86_64docker-ce-cli-1:20.10.21-3.el8.x86_64                              docker-ce-rootless-extras-20.10.21-3.el8.x86_64             docker-compose-plugin-2.12.2-3.el8.x86_64docker-scan-plugin-0.21.0-3.el8.x86_64                             fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64   fuse3-3.2.1-12.el8.x86_64fuse3-libs-3.2.1-12.el8.x86_64                                     libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64         slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64Complete

CentOS 8 中安装 Docker 出现和 Podman 冲突的问题

root@monitor ~]# yum install docker-ce docker-ce-cli containerd.io
CentOS Linux 8 - AppStream                      669 kB/s | 6.2 MB     00:09
CentOS Linux 8 - BaseOS                         351 kB/s | 2.3 MB     00:06
Docker CE Stable - x86_64                       1.1 kB/s | 7.1 kB     00:06
Docker CE Nightly - x86_64                      327  B/s | 2.6 kB     00:08
Error:Problem 1: problem with installed package podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64- package podman-2.0.5-5.module_el8.3.0+512+b3b58dca.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed- package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64- package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64- cannot install the best candidate for the job- package runc-1.0.0-64.rc10.module_el8.3.0+479+69e2ae26.x86_64 is filtered out by modular filteringProblem 2: problem with installed package buildah-1.15.1-2.module_el8.3.0+475+c50ce30b.x86_64- package buildah-1.15.1-2.module_el8.3.0+475+c50ce30b.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed- package docker-ce-3:20.10.1-3.el8.x86_64 requires containerd.io >= 1.4.1, but none of the providers can be installed- package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64- package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64- package containerd.io-1.4.1-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64- package containerd.io-1.4.1-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64- package containerd.io-1.4.3-3.el8.x86_64 conflicts with runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64- package containerd.io-1.4.3-3.el8.x86_64 obsoletes runc provided by runc-1.0.0-68.rc92.module_el8.3.0+475+c50ce30b.x86_64- cannot install the best candidate for the job- package runc-1.0.0-56.rc5.dev.git2abd837.module_el8.3.0+569+1bada2e4.x86_64 is filtered out by modular filtering- package runc-1.0.0-64.rc10.module_el8.3.0+479+69e2ae26.x86_64 is filtered out by modular filtering

解决方法

yum erase podman buildah

5.配置阿里云镜像加速器

1)登录阿里云
阿里云URL
2)控制台->容器镜像服务
执行命令

测试:

[root@localhost yum.repos.d]# sudo docker run hello-worldHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/

5、启动docker

[root@localhost yum.repos.d]# sudo systemctl start docker

6、测试

[root@localhost yum.repos.d]#  sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:e18f0a777aefabe047a671ab3ec3eed05414477c951ab1a6f352a06974245fe7
Status: Downloaded newer image for hello-world:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/

二、常用命令

1、帮助启动类命令

1、启动docker

systemctl start docker

2、停止docker

systemctl stop docker

3、查看docker状态

systemctl status docker

4、重启

systemctl restart docker

5、开机启动

systemctl enable docker

6、查看信息

docker info

7、查看帮助文档

docker --help

8、查看具体帮助文档

docker  命令 --help

2、镜像命令

1、列出本地主机上的镜像

docker images [-a] [-q]
[root@localhost yum.repos.d]# docker images -a
仓库源        镜像的版本    镜像id     镜像创建时间     镜像大小
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   13 months ago   13.3kB

2、查询镜像

[root@localhost /]# docker search --limit 5 redis
名字                      说明描述                                        点赞        是否官方
NAME                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED(自动构建)
redis                    Redis is an open source key-value store that…   11537     [OK]
redislabs/redisinsight   RedisInsight - The GUI for Redis                69
redislabs/redisearch     Redis With the RedisSearch module pre-loaded…   55
redislabs/redis          Clustered in-memory database engine compatib…   35
redislabs/rebloom        A probablistic datatypes module for Redis       21                   [OK]

3.拉取镜像

[root@localhost /]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
a2abf6c4d29d: Pull complete
c7a4e4382001: Pull complete
4044b9ba67c9: Pull complete
c8388a79482f: Pull complete
413c8bb60be2: Pull complete
1abfd3011519: Pull complete
Digest: sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
[root@localhost /]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
tomcat        latest    fb5657adc892   10 months ago   680MB
redis         latest    7614ae9453d1   10 months ago   113MB
hello-world   latest    feb5d9fea6a5   13 months ago   13.3kB

4.查看镜像、容器、数据卷所占空间

[root@localhost /]# docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          3         1         792.3MB   792.3MB (99%)
Containers      2         0         0B        0B
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B

5.删除镜像

[root@localhost /]# docker rmi -f feb5d9fea6a5
Untagged: hello-world:latest
Untagged: hello-world@sha256:e18f0a777aefabe047a671ab3ec3eed05414477c951ab1a6f352a06974245fe7
Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
[root@localhost /]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
tomcat       latest    fb5657adc892   10 months ago   680MB
redis        latest    7614ae9453d1   10 months ago   113MB

3、容器命令

1、拉取CentOS镜像

[root@localhost /]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@localhost /]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
tomcat       latest    fb5657adc892   10 months ago   680MB
redis        latest    7614ae9453d1   10 months ago   113MB
centos       latest    5d0da3dc9764   13 months ago   231MB
[root@localhost /]#

2、启动一个CentOS容器

[root@localhost /]# docker run -it  centos
[root@7b11c8d2b38d /]# ls -al
total 0
drwxr-xr-x.   1 root root   6 Nov  9 06:10 .
drwxr-xr-x.   1 root root   6 Nov  9 06:10 ..
-rwxr-xr-x.   1 root root   0 Nov  9 06:10 .dockerenv
lrwxrwxrwx.   1 root root   7 Nov  3  2020 bin -> usr/bin
drwxr-xr-x.   5 root root 360 Nov  9 06:10 dev
drwxr-xr-x.   1 root root  66 Nov  9 06:10 etc
drwxr-xr-x.   2 root root   6 Nov  3  2020 home
lrwxrwxrwx.   1 root root   7 Nov  3  2020 lib -> usr/lib
lrwxrwxrwx.   1 root root   9 Nov  3  2020 lib64 -> usr/lib64
drwx------.   2 root root   6 Sep 15  2021 lost+found
drwxr-xr-x.   2 root root   6 Nov  3  2020 media
drwxr-xr-x.   2 root root   6 Nov  3  2020 mnt
drwxr-xr-x.   2 root root   6 Nov  3  2020 opt
dr-xr-xr-x. 221 root root   0 Nov  9 06:10 proc
dr-xr-x---.   2 root root 162 Sep 15  2021 root
drwxr-xr-x.  11 root root 163 Sep 15  2021 run
lrwxrwxrwx.   1 root root   8 Nov  3  2020 sbin -> usr/sbin
drwxr-xr-x.   2 root root   6 Nov  3  2020 srv
dr-xr-xr-x.  13 root root   0 Nov  9 03:00 sys
drwxrwxrwt.   7 root root 171 Sep 15  2021 tmp
drwxr-xr-x.  12 root root 144 Sep 15  2021 usr
drwxr-xr-x.  20 root root 262 Sep 15  2021 var
[root@7b11c8d2b38d /]# ^C
[root@7b11c8d2b38d /]# exit
exit
[root@localhost /]#

-i:以交互模式运行容器,通常与 -t 同时使用;

-t:为容器重新分配一个伪输入终端,通常与 -i 同时使用;

也即启动交互式容器(前台有伪终端,等待交互);

3、列出当前正在运行的容器

docker ps [options]

OPTIONS说明(常用):

-a :列出当前所有正在运行的容器+历史上运行过的
-l :显示最近创建的容器。
-n:显示最近n个创建的容器。
-q :静默模式,只显示容器编号。

4、退出容器

1) exit  退出容器的同事通知容器
2) ctrl+p+q   退出不停止

5.停止容器

docker stop [容器ID或者容器名字]
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
b911f3712135   centos    "/bin/bash"   2 minutes ago   Up 2 minutes             agitated_jepsen
[root@localhost ~]# docker stop b911f3712135
b911f3712135
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@localhost ~]#

6.启动一个已经停止的容器

docker start [容器ID]

7、重启容器

docker restart [容器ID]

8.强制停止容器

docker kill [容器ID]

9、删除已经停止的容器

docker rm [容器ID]

10.启动一个守护式容器

[root@localhost ~]# docker run -d --name tomcat-2 tomcat
1189b4a1f588438a25d05bb4a4f06e0216c8e7ad7dd196b6e56711a17a39fd15
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED         STATUS         PORTS      NAMES
1189b4a1f588   tomcat    "catalina.sh run"   5 seconds ago   Up 5 seconds   8080/tcp   tomcat-2

11.查看容器日志

docker logs [容器ID]

12.进入到容器内部

docker exec -it [容器ID] /bin/bash

13.拷贝容器内部文件到宿主机

docker exec -it [容器ID] /bin/bash
[root@localhost /]# docker cp b8bf10e3500e:/usr/local/tomcat/a.txt /a.txt

14.导入导出容器

docker export b8bf10e3500e > tomcat-1.tar.gz
cat ./tomcat-1.tar.gz | docker import - qlx/tomcat-1:1.0.0
docker run -d  --name tomcat1-0 tomcat1 /bin/bash
[root@localhost /]# docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED          STATUS          PORTS                                                 NAMES
3cc1a39443d9   tomcat    "catalina.sh run"   32 minutes ago   Up 32 minutes   8080/tcp, 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   tomcat-2
b8bf10e3500e   tomcat    "catalina.sh run"   34 minutes ago   Up 34 minutes   8080/tcp                                              tomcat-1
[root@localhost /]# docker export b8bf10e3500e > tomcat-1.tar.gz
[root@localhost /]# ls -al
total 667368
dr-xr-xr-x.  18 root root      4096 Nov  9 15:38 .
dr-xr-xr-x.  18 root root      4096 Nov  9 15:38 ..
-rw-r--r--.   1 root root         4 Oct 28 16:06 a
-rw-r--r--.   1 root root         7 Nov  9 15:11 a.txt
-rw-r--r--.   1 root root         4 Oct 28 16:07 b
lrwxrwxrwx.   1 root root         7 Jun 22  2021 bin -> usr/bin
dr-xr-xr-x.   5 root root      4096 Oct 25 14:20 boot
drwxr-xr-x.   6 root root       219 Oct 27 11:45 data
drwxr-xr-x.  19 root root      3160 Nov  9 11:01 dev
drwxr-xr-x. 151 root root      8192 Nov  9 11:01 etc
drwxr-xr-x.   3 root root        17 Oct 25 14:19 home
lrwxrwxrwx.   1 root root         7 Jun 22  2021 lib -> usr/lib
lrwxrwxrwx.   1 root root         9 Jun 22  2021 lib64 -> usr/lib64
drwxr-xr-x.   2 root root         6 Jun 22  2021 media
drwxr-xr-x.   3 root root        18 Oct 25 14:11 mnt
drwxr-xr-x.   3 root root        24 Nov  8 15:12 opt
dr-xr-xr-x. 265 root root         0 Nov  9 11:00 proc
dr-xr-x---.  16 root root      4096 Nov  9 14:53 root
drwxr-xr-x.  42 root root      1260 Nov  9 15:26 run
lrwxrwxrwx.   1 root root         8 Jun 22  2021 sbin -> usr/sbin
drwxr-xr-x.   2 root root         6 Jun 22  2021 srv
dr-xr-xr-x.  13 root root         0 Nov  9 11:00 sys
drwxrwxrwt.  17 root root      4096 Nov  9 15:37 tmp
-rw-r--r--.   1 root root 683334144 Nov  9 15:40 tomcat-1.tar.gz
drwxr-xr-x.  13 root root       158 Oct 25 14:10 usr
drwxr-xr-x.  22 root root      4096 Oct 25 14:20 var
[root@localhost /]# docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED          STATUS          PORTS                                                 NAMES
3cc1a39443d9   tomcat    "catalina.sh run"   34 minutes ago   Up 34 minutes   8080/tcp, 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   tomcat-2
b8bf10e3500e   tomcat    "catalina.sh run"   36 minutes ago   Up 36 minutes   8080/tcp                                              tomcat-1
[root@localhost /]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
tomcat       latest    fb5657adc892   10 months ago   680MB
redis        latest    7614ae9453d1   10 months ago   113MB
centos       latest    5d0da3dc9764   13 months ago   231MB
[root@localhost /]# docker stop b8bf10e3500e
b8bf10e3500e
[root@localhost /]# docker rm b8bf10e3500e
b8bf10e3500e
[root@localhost /]# docker ps -a
CONTAINER ID   IMAGE     COMMAND             CREATED          STATUS          PORTS                                                 NAMES
3cc1a39443d9   tomcat    "catalina.sh run"   34 minutes ago   Up 34 minutes   8080/tcp, 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   tomcat-2
[root@localhost /]# cat ./tomcat-1.tar.gz | docker import - qlx/tomcat-1:1.0.0
sha256:1803b1bc12e55fd211b871de704a123224f211fb4d9431c5de41d336902d3da4
[root@localhost /]# docker images
REPOSITORY     TAG       IMAGE ID       CREATED          SIZE
qlx/tomcat-1   1.0.0     1803b1bc12e5   10 seconds ago   672MB
tomcat         latest    fb5657adc892   10 months ago    680MB
redis          latest    7614ae9453d1   10 months ago    113MB
centos         latest    5d0da3dc9764   13 months ago    231MB
[root@localhost /]#

三.linux下docker的卸载!

1、首先关闭docker容器

#systemctl status docker 查看docker的状态
#systemctl stop  docker  停止docker容器 

2、查看安装docker的文件包

#docker list installed |grep docker 

利用rpm -qa查看docker的源文件

#rpm -qa |grep docker 

3、删除所有docker包

#yum -y remove docker*.x86_64 

4、删除docker的镜像文件!

默认存在目录是:cd /var/lib/docker

#cd /var/lib/docker
#rm -rf /var/lib/docker

Docker(安装常用命令)相关推荐

  1. Docker客户端常用命令整理

    之前在 https://blog.csdn.net/fengbingchun/article/details/109584460 中介绍过在Windows10家庭版和Ubuntu16.04上安装Doc ...

  2. Docker 精通之常用命令

    Docker 精通系列 Docker 精通之入门 Docker 精通之微服务 Docker 精通之常用命令 Docker 精通之 Dockerfile 配置文件路径 /etc/sysconfig/do ...

  3. 【docker11】docker安装常用软件

    目录 docker安装常用软件 1.安装软件说明 1.安装tomcat 2.安装mysql 2.1简单版 2.2实战版本 3.安装redis docker安装常用软件 1.安装软件说明 框架图 总体步 ...

  4. 四、docker系列之docker安装常用软件

    docker安装常用软件 目录 docker安装常用软件 docker安装运行redis 一.DockerHup redis仓库 二.镜像拉取 三.镜像启动 四.参数解析 docker安装运行mysq ...

  5. Docker安装常用软件-Mysql

    一.生成镜像 方法一:通过Dockerfile 1.新建目录 mysql  D:\docker\docker应用池\mysql mysql目录下创建三个目录 /home/mysql /logs /co ...

  6. Docker初学3:Docker的常用命令

    Docker的常用命令 帮助命令 帮助命令可以在我们遇到不懂的命令时帮助我们去了解它们怎么使用. docker version # 显示 Docker 版本信息. docker info # 显示 D ...

  7. Docker镜像常用命令

    Docker镜像常用命令 查看镜像列表 docker images $ docker images >>> REPOSITORY TAG IMAGE ID CREATED SIZE ...

  8. 久等了!Docker容器常用命令

    点击蓝色"程序员的时光 "关注我 ,标注"星标",及时阅读最新技术文章 写在前面: 小伙伴儿们,大家好!上一篇我们讲到Docker的常用命令--详细齐全!Doc ...

  9. Docker的RUN流程和Docker原理、Docker的常用命令、其他命令

    Docker的RUN流程和Docker原理 Run流程 底层原理 Docker是怎么工作的 Docker为什么比VM快 Docker的常用命令 帮助命令 镜像命令 查看镜像 搜索镜像 下载镜像 指定版 ...

  10. docker的常用命令(三)

    docker的常用命令 帮助命令 docker version # 显示docker版本信息 docker info # 显示docker的系统,包含镜像和容器的数量 docker 命令 --help ...

最新文章

  1. mysql 5.7 json函数_Mysql5.7中对于JSON函数设置的案例详细说明
  2. create-react-app留言板
  3. Java中定义VO事件的问题
  4. Delphi中文件名函数-路径、名称、子目录、驱动器、扩展名
  5. ViewState与Session 的重要区别
  6. 7、leetcode410 分割数组的最大值
  7. Qt实践录:非窗体代码片段
  8. 经典面试题:有序矩阵的快速查找
  9. bzoj1452 [JSOI2009]Count
  10. 使用SecureCRT工具上传、下载文件的两种方法
  11. 使用BoundsChecker检测内存泄漏
  12. Linux课程--实验四 shell 编程
  13. 16光8电全千兆宽温工业交换机16千兆光8千兆网口机架式网管型工业级以太网交换机
  14. 微信公众号开发中分享功能 分享微信朋友圈/微信好友
  15. 关于堡垒机的原理以及如何配置
  16. ubuntu18.04 设置字体样式, 调整字体大小
  17. 如何实现设备的预测性维护
  18. 凭借ZTMAPGIS开发系统,打造智慧林业巡护“一块屏”,全面加强森林资源保护新时代
  19. Scipy.sparse模块中coo_matrix、csc_matrix、csr_matrix区别
  20. 使用原始的XML资源

热门文章

  1. 计算机不认第二个硬盘,Windows 10无法识别第二个硬盘 | MOS86
  2. jmeter(二):简单web测试流程
  3. 精准营销服务平台设计-基于大数据和AI的商业智能平台
  4. docker中使用aspose word转pdf 乱码问题
  5. 计算机主要分为台式机和什么,计算机基础知识-台式机.ppt
  6. QT使用串口与RS485设备通讯
  7. vc不能添加文件的小工具
  8. JAVA学生信息管理系统——增删查改
  9. 晶闸管静态参数测试系统
  10. 2021年最新ABAQUS复合材料建模仿真与应用