docker安装
自带源安装
如有旧版本,先卸载旧的: sudo remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine
安装依赖 [root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
配置docker源
在.repo源中添加: [docker-ce-stable] name=Docker CE Stable - $basearch baseurl=http://10.35.186.100:8081/repository/docker/linux/centos/$releasever/$basearch/stable enabled=1 gpgcheck=0 gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[root@ruoyi ~]# rm -rf /var/lib/docker
[root@ruoyi ~]# yum list installed | grep docker
# 官方源 [root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # 阿里源 [root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装最新版本
# 安装最新版 [root@localhost ~]# yum -y install docker-ce docker-ce-cli containerd.io
#配置加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://pilvpemn.mirror.aliyuncs.com",
"https://docker.m.daocloud.io",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn"
],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
#注意:一定注意编码问题,出现错误---查看命令:journalctl -amu docker 即可发现错误
开机自启
[root@localhost ~]# systemctl enable --now docker
重载docker服务
[root@localhost ~]# systemctl daemon-reload && systemctl restart docker
或者:
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start
拉取代码
[root@lvs-server ~]# docker pull mysql:8.0.38-oraclelinux9 --拉取指定版本 8.0.38-oraclelinux9: Pulling from library/mysql d9a40b27c30f: Pull complete c3e750b66554: Pull complete 8c7ce6c9ed47: Pull complete 07b15d10f125: Pull complete 36aa6d82134c: Pull complete ff7ba837a054: Pull complete 2434679df156: Pull complete 6bf60bd2cde3: Pull complete 4914dbc1b9fc: Pull complete a24e196bc810: Pull complete 068a7d33dd38: Pull complete Digest: sha256:5c78edf3b6f4ac8aa30df543bba8a4db2ac009f91271b207d4cbeed98b9d9984 Status: Downloaded newer image for mysql:8.0.38-oraclelinux9 docker.io/library/mysql:8.0.38-oraclelinux9
查看所有镜像
[root@lvs-server ~]# docker images -a REPOSITORY TAG IMAGE ID CREATED SIZE mysql 8.0.38-oraclelinux9 6c54cbcf775a 2 weeks ago 572MB rockylinux 9.3 9cc24f05f309 7 months ago 176MB
只看uid
[root@lvs-server ~]# docker images -q 6c54cbcf775a 9cc24f05f309
查看完整信息
[root@lvs-server ~]# docker images --no-trunc REPOSITORY TAG IMAGE ID CREATED SIZE mysql 8.0.38-oraclelinux9 sha256:6c54cbcf775a2d79070921081941047e31da3df7a70d8bfae77e32e817160bae 2 weeks ago 572MB rockylinux 9.3 sha256:9cc24f05f309508aa852967ab1e3b582b302afc92605c24ce27715c683acd805 7 months ago 176MB
从DockerHub官网上查看镜像
[root@lvs-server ~]# docker search nginx/image_name
[root@lvs-server ~]# docker pull mysql/nginx --默认拉取的是最后一个代码