CentO7.9安装Docker

文章目录

CentO7.9安装Docker

删除旧版本的Docker

复制代码
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

这个可能是匹配不到的,来个狠一点的

复制代码
sudo yum remove docker*

带有Docker的全部删掉

安装Docker仓库

复制代码
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

安装Docker

安装最新版本

安装Docker最新版,不带版本的默认最新版本

复制代码
 sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

安装指定版本

查找docker-ce的版本

复制代码
[root@WDQCVM ~]# yum list docker-ce --showduplicates | sort -r

 * updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
 * extras: mirrors.aliyun.com
docker-ce.x86_64            3:24.0.5-1.el7                      docker-ce-stable
docker-ce.x86_64            3:24.0.4-1.el7                      docker-ce-stable
docker-ce.x86_64            3:24.0.3-1.el7                      docker-ce-stable
docker-ce.x86_64            3:24.0.2-1.el7                      docker-ce-stable
docker-ce.x86_64            3:24.0.1-1.el7                      docker-ce-stable

查找docker-ce-cli的版本

复制代码
[root@WDQCVM ~]# yum list docker-ce-cli --showduplicates | sort -r
 * updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
Installed Packages
 * extras: mirrors.aliyun.com
docker-ce-cli.x86_64             1:24.0.5-1.el7                docker-ce-stable 
docker-ce-cli.x86_64             1:24.0.5-1.el7                @docker-ce-stable
docker-ce-cli.x86_64             1:24.0.4-1.el7                docker-ce-stable 
docker-ce-cli.x86_64             1:24.0.3-1.el7                docker-ce-stable 
docker-ce-cli.x86_64             1:24.0.2-1.el7                docker-ce-stable 
docker-ce-cli.x86_64             1:24.0.1-1.el7                docker-ce-stable 

将参数替换即可

通用示例

复制代码
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-buildx-plugin docker-compose-plugin

指定版本示例

复制代码
sudo yum install docker-ce-24.0.4-1.el7  docker-ce-cli-24.0.4-1.el7 containerd.io docker-buildx-plugin docker-compose-plugin

Centos7.9版本安装Docker指定版本时,安装了好多次这么设置版本号才成功,在软件包名称和版本号之间不需要添加数字和冒号,但官网给出的实例是带有:的,费解。

校验是否成功

复制代码
[root@WDQCVM ~]# sudo systemctl start docker
[root@WDQCVM ~]# sudo docker --version
Docker version 24.0.4, build 3713ee1
[root@WDQCVM ~]# 

有以下这些就可说明成功了

复制代码
[root@WDQCVM ~]# sudo docker run hello-world

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/

[root@WDQCVM ~]# 

Docker安装个NGINX

复制代码
[root@WDQCVM ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
52d2b7f179e3: Pull complete 
fd9f026c6310: Pull complete 
055fa98b4363: Pull complete 
96576293dd29: Pull complete 
a7c4092be904: Pull complete 
e3b6889c8954: Pull complete 
da761d9a302b: Pull complete 
Digest: sha256:13d22ec63300e16014d4a42aed735207a8b33c223cff19627dd3042e5a10a3a0
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@WDQCVM ~]# 

查看Docker镜像

复制代码
[root@WDQCVM ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
nginx         latest    eea7b3dcba7e   27 hours ago   187MB
hello-world   latest    9c7a54a9a43c   3 months ago   13.3kB

运行

复制代码
[root@WDQCVM ~]# docker run --name nginx -p 8080:80 -d nginx
d1b23e05201a232eb57c2458423b88cee5dc9a27464bb680978676dcd4dd741a
[root@WDQCVM ~]#

查看Docker进程

复制代码
[root@WDQCVM ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
d1b23e05201a   nginx     "/docker-entrypoint...."   7 seconds ago   Up 4 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   nginx
[root@WDQCVM ~]# 

查看启动端口

复制代码
[root@WDQCVM ~]# ss -ltnp |grep 8080
LISTEN     0      128          *:8080                     *:*                   users:(("docker-proxy",pid=11654,fd=4))
LISTEN     0      128       [::]:8080                  [::]:*                   users:(("docker-proxy",pid=11661,fd=4))
[root@WDQCVM ~]# 

停止Docker容器

复制代码
[root@WDQCVM ~]# docker stop nginx
nginx
[root@WDQCVM ~]# 
[root@WDQCVM ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@WDQCVM ~]# 

Docker官网

相关推荐
腥臭腐朽的日子熠熠生辉21 分钟前
nest js docker 化全流程
开发语言·javascript·docker
酒醉的胡铁23 分钟前
Docker Desktop 数据迁移完整流程(Windows 10/11 x64)
windows·docker·容器
纯洁的小魔鬼28 分钟前
Dockerfile 指令
docker·镜像·dockerfile
❀͜͡傀儡师32 分钟前
Kubernetes 1.34.3部署PostgresSQL的v18.1
云原生·容器·kubernetes·postgressql
Y.O.U..39 分钟前
Kubernetes-资源清单(1)
容器·kubernetes
释怀不想释怀1 小时前
Docker(安装软件)
运维·docker·容器
超龄超能程序猿1 小时前
Docker常用中间件部署笔记:MongoDB、Redis、MySQL、Tomcat快速搭建
笔记·docker·中间件
奔波霸的伶俐虫1 小时前
windows docker desktop 安装修改镜像学习
学习·docker·容器
原神启动11 小时前
K8S(六)—— 企业级,Rancher安装配置与核心功能实操
容器·kubernetes·rancher
阿杰 AJie1 小时前
安装 docker.io(不走外网 Docker 域名)
docker·容器·eureka