首页>软件资讯>常见问题

常见问题

docker环境部署

发布时间:2025-05-15 13:25:01人气:82


Docker是一个容器管理技术,它是一个用于开发、发布和运行应用程序的开放平台。


Docker是一组平台即服务(PaaS)的产品。它基于操作系统层级的虚拟化技术,将软件与其依赖项打包为容器。托管容器的软件称为Docker引擎。Docker能够帮助开发者在轻量级容器中自动部署应用程序,并使得不同容器中的应用程序彼此隔离,高效工作。


1.卸载旧版本的docker环境

移除旧版本,不删除软件包


[root@docker01 ~]# yum remove docker                   docker-client                   docker-client-latest                   docker-common                   docker-latest                   docker-latest-logrotate                   docker-logrotate                   docker-engine#删除数据目录[root@docker01 ~]#  rm -rf /var/lib/docker  /var/lib/containerd

2.添加软件源


[root@docker01 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2[root@docker01 ~]# curl -s -o /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo[root@docker01 ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3.查看现有docker版本


[root@docker01 ~]# yum list docker-ce --showduplicates | sort -r * updates: mirrors.aliyun.comLoading mirror speeds from cached hostfileLoaded plugins: fastestmirror * extras: mirrors.aliyun.comdocker-ce.x86_64            3:26.1.4-1.el7                      docker-ce-stabledocker-ce.x86_64            3:26.1.3-1.el7                      docker-ce-stabledocker-ce.x86_64            3:26.1.2-1.el7                      docker-ce-stable

4.yum方式安装指定版本docker



[root@docker02 ~]# yum -y install docker-ce-26.1.4 docker-ce-cli-26.1.4 containerd.io

5.基于rpm离线安装docker


[root@docker02 ~]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-26.1.4-1.el7.x86_64.rpm[root@docker02 ~]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-26.1.4-1.el7.x86_64.rpm[root@docker02 ~]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.6.33-3.1.el7.x86_64.rpm[root@docker02 ~]# yum -y localinstall *.rpm

6.二进制安装docker(centos,Ubuntu)


# 下载安装包[root@docker01 ~]# wget https://download.docker.com/linux/static/stable/x86_64/docker-28.0.4.tgz# 解压软件包[root@docker01 ~]# mkdir -pv /liux/softwares[root@docker01 ~]# tar xf docker-docker-28.0.4.tgz -C /liux/softwares/# 创建软链接到环境变量[root@docker01 ~]# ln -sv /liux/softwares/docker/* /usr/bin/# 编写启动脚本[root@docker01 ~]# cat > /usr/lib/systemd/system/docker.service <<EOF[Unit]Description=liux Linux Docker Application Container Engine[Service]Type=simpleExecStart=/usr/local/bin/dockerd[Install]WantedBy=multi-user.targetEOF# 启动docker服务并设置开机自启动[root@docker01 ~]# systemctl daemon-reload[root@docker01 ~]# systemctl enable --now docker

6.添加镜像加速器

[root@docker01 ~]# mkdir -p /etc/docker[root@docker01 ~]# tee /etc/docker/daemon.json <<-'EOF'{  "registry-mirrors": ["https://k0jntw7k.mirror.aliyuncs.com",                       "https://docker.m.daocloud.io",                       "https://dockerpull.com",                       "https://docker.registry.cyou",                       "https://atomhub.openatom.cn",                       "https://docker.1panel.live",                       "https://hub.rat.dev",                       "https://docker.awsl9527.cn",                       "https://do.nark.eu.org",                       "https://docker.ckyl.me",                       "https://hub.uuuadc.top",                       "https://docker.chenby.cn"                      ]}EOF

7.启动docker


[root@docker01 ~]# systemctl daemon-reload[root@docker01 ~]# systemctl enable --now docker[root@docker01 ~]# systemctl  status docker

8.测试docker是否安装成功


[root@docker01 ~]# docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worlde6590344b1a5: Pull complete Digest: sha256:c41088499908a59aae84b0a49c70e86f4731e588a737f1637e73c8c09d995654Status: 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/

# 查看镜像[root@docker01 ~]# docker imagesREPOSITORY    TAG       IMAGE ID       CREATED        SIZEhello-world   latest    74cc54e27dc4   3 months ago   10.1kB

9.开启docker自动补齐功能


[root@docker01 ~]# yum -y install bash-completion[root@docker01 ~]# source /usr/share/bash-completion/bash_completion

10.卸载docker环境(有需要就可以操作额)


[root@docker01 ~]# yum -y remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras[root@docker01 ~]# rm -rf /var/lib/docker  /var/lib/containerd

至此,docker环境已经安装完毕



上一条:安装Anaconda以及集成开发工具

下一条:Docker的三大核心概念:镜像、容器与仓库