在 CentOS 系统上安装 Docker,您可以按照以下步骤进行操作。请注意,这里的指导适用于 CentOS 7 及以上版本。假设您已通过 SSH(如 Xshell)或其他方式远程连接到您的 CentOS 系统,系统可以访问互联网,并且拥有足够的权限进行软件安装。现在开始万物容器化之旅吧!
1、配置yum源
[root@operater yum.repos.d]# vi CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
/mirrors.aliyun.com /mirrors.aliyun.com/gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
2、安装依赖项
[root@operater yum.repos.d]# yum install -y yum-utils
Loaded plugins: fastestmirror
Repository 'contrib': Error parsing config: Error parsing "enabled = '0n/mirrors.aliyun.com /mirrors.aliyun.com/gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7'": invalid boolean value
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirror.nyist.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do
3、配置安装源
[root@operater yum.repos.d]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
Repository 'contrib': Error parsing config: Error parsing "enabled = '0n/mirrors.aliyun.com /mirrors.aliyun.com/gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7'": invalid boolean value
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@iZ4uj01kbf6bikb5ik7s83Z yum.repos.d]# ll
total 16
-rw-r--r-- 1 root root 2514 Apr 16 13:59 CentOS-Base.repo
-rw-r--r-- 1 root root 2081 Apr 16 14:39 docker-ce.repo
4、开始安装docker
[root@operater yum.repos.d]# yum install docker-ce docker-ce-cli containerd.io -y
Loaded plugins: fastestmirror
Repository 'contrib': Error parsing config: Error parsing "enabled = '0n/mirrors.aliyun.com /mirrors.aliyun.com/gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7'": invalid boolean value
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirror.nyist.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
docker-ce-stable | 3.5 kB 00:00:00
Package 3:docker-ce-26.0.1-1.el7.x86_64 already installed and latest version
Package 1:docker-ce-cli-26.0.1-1.el7.x86_64 already installed and latest version
Package containerd.io-1.6.31-3.1.el7.x86_64 already installed and latest version
Nothing to do
5、启动 docker 并设置开机启动
[root@operater yum.repos.d]# systemctl start docker
[root@operater yum.repos.d]# systemctl enable docker
6、查看docker 版本
[root@operater bin]# docker version
Client: Docker Engine - Community
Version: 26.0.1
API version: 1.45
Go version: go1.21.9
Git commit: d260a54
Built: Thu Apr 11 10:56:30 2024
OS/Arch: linux/amd64
Context: default
7、运行docker 服务(nginx为例)
[root@operater bin]# docker run -d --name nginx --network host --restart always -v /nginx:/etc/nginx/conf.d nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
13808c22b207: Pull complete
6fcdffcd79f0: Pull complete
fbf231d461b3: Pull complete
c9590dd9c988: Pull complete
b4033143d859: Pull complete
abaefc5fcbde: Pull complete
bcef83155b8b: Pull complete
Digest: sha256:9ff236ed47fe39cf1f0acf349d0e5137f8b8a6fd0b46e5117a401010e56222e1
Status: Downloaded newer image for nginx:latest
c04818157892b87e918eb576c0f06570ca14fa65d5a7351aaaafb4c1881752ec
8、查看docker服务
[root@operater bin]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c04818157892 nginx "/docker-entrypoint.…" 10 seconds ago Up 8 seconds nginx
9、docker的卸载
# 卸载 yum remove docker-ce docker-ce-cli containerd.io -y
[root@operater yum.repos.d]# yum remove docker-ce docker-ce-cli containerd.io -y
Loaded plugins: fastestmirror
Repository 'contrib': Error parsing config: Error parsing "enabled = '0n/mirrors.aliyun.com /mirrors.aliyun.com/gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7'": invalid boolean value
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.6.31-3.1.el7 will be erased
---> Package docker-ce.x86_64 3:26.0.1-1.el7 will be erased
--> Processing Dependency: docker-ce for package: docker-ce-rootless-extras-26.0.1-1.el7.x86_64
---> Package docker-ce-cli.x86_64 1:26.0.1-1.el7 will be erased
--> Running transaction check
---> Package docker-ce-rootless-extras.x86_64 0:26.0.1-1.el7 will be erased
# 删除关联文件 rm -rf /var/lib/docker
[root@operater yum.repos.d]# rm -rf /var/lib/docker
原文始发于微信公众号(云网数端):CentOS 系统上安装 Docker
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/280222.html