Linux安装dockers
1、查看版本信息是否符合安装条件:
- 用户使用linux为64位操作系统;
- 系统内核版本至少在3.10以上。
[root@wangliukun ~]# uname -a
Linux wangliukun 6.5.6 #1 SMP PREEMPT_DYNAMIC Tue Oct 10 09:17:13 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux
[root@wangliukun ~]# uname -r
6.5.6
2、yum更新
使用Root权限登录 Centos。确保yum包更新到最新。
[root@wangliukun ~]# yum update
3、卸载原有docker
[root@wangliukun ~]# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
4、安装docker(使用阿里云yum安装)
[root@wangliukun ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
已安装:
yum-utils.noarch 0:1.1.31-54.el7_8
作为依赖被安装:
python-kitchen.noarch 0:1.1.1-5.el7
完毕!
[root@wangliukun ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
遇到问题:
This system is not registered with an entitlement server. You can use subscription-manager to register.
原因:
Red Hat Subscription Manager订阅管理器,它会让你一直register
解决方法: 禁用就好。
[root@wangliukun ~]#vi /etc/yum/pluginconf.d/subscription-manager.conf
[main]
enabled=0
重新添加软件源信息即可
[root@wangliukun ~]# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
[root@wangliukun ~]# yum makecache fast
[root@wangliukun ~]# yum -y install docker-ce
已安装:
docker-ce.x86_64 3:25.0.3-1.el7
作为依赖被安装:
containerd.io.x86_64 0:1.6.28-3.1.el7
docker-buildx-plugin.x86_64 0:0.12.1-1.el7
docker-ce-cli.x86_64 1:25.0.3-1.el7
docker-ce-rootless-extras.x86_64 0:25.0.3-1.el7
docker-compose-plugin.x86_64 0:2.24.6-1.el7
完毕!
[root@wangliukun ~]# start docker.service
[root@wangliukun ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@wangliukun ~]# docker version
Client: Docker Engine - Community
Version: 25.0.3
API version: 1.44
Go version: go1.21.6
Git commit: 4debf41
Built: Tue Feb 6 21:17:10 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 25.0.3
API version: 1.44 (minimum version 1.24)
Go version: go1.21.6
Git commit: f417435
Built: Tue Feb 6 21:16:08 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.28
GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@wangliukun ~]#
[root@wangliukun ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d
Status: 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/
-
配置docker加速器(阿里云)
-
可能出现问题:无法拉取hello-world
-
[root@wangliukun ~]# docker run hello-world Unable to find image 'hello-world:latest' locally Trying to pull repository docker.io/library/hello-world ... /usr/bin/docker-current: missing signature key. See '/usr/bin/docker-current run --help'.
意思是docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取到镜像。
意思是docker在本地没有找到hello-world镜像,也没有从docker仓库中拉取到镜像。
- 异常原因:
这是因为docker服务器在国外,基于网速与“和谐墙”的问题,所以我们在国内操作国外镜像可能无法正常拉取,这需要我们为docker设置国内的阿里云镜像加速器。
- 解决方法:
1、登录阿里云 - 容器 Hub 服务控制台后,点击“镜像加速器”标签,找到镜像工具–>镜像加速
2、根据手册配置文件,添加阿里云镜像:
[root@wangliukun ~]#vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://v97vyodn.mirror.aliyuncs.com"]
}
#systemctl restart docker
#sudo systemctl status docker
3、重新拉取即可成功
下一章:Docker镜像