Docker安装脚本
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all
yum makecache
yum -y install docker-ce
systemctl start docker
systemctl enable docker
cat << EOF>> /etc/docker/daemon.json
{
"registry-mirrors": ["https://7xdlztz4.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
使用yum安装Docker
1.安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
2.配置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all
yum makecache
3.安装docker
(旧版本的docker叫做docker或docker-engine)
yum -y install docker-ce
启动docker前关闭防火墙ß
systemctl start docker
systemctl enable docker
提示
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
4. 查看安装是否成功,有docker0说明环境部署完成
ifconfig
二进制安装Docker
1、下载二进制安装包
https://download.docker.com/linux/static/stable/x86_64/docker-20.10.0.tgz #docker官方镜像
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/static/stable/x86_64/docker-20.10.0.tgz #清华大学镜像
https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/docker-20.10.0.tgz #阿里镜像
2、解压docker二进制包
tar zvfx ./docker-20.10.0.tgz -C /usr/local/
cd /usr/local/
mv docker docker-20.10.0
ln -s docker-20.10.0 docker
3、添加环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/docker
source /etc/profile
4、添加启动服务脚本
vim /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target
Wants=docker-storage-setup.service
[Service]
Type=notify
NotifyAccess=main
Environment=PATH=/usr/local/docker:/usr/bin:/usr/sbin
ExecStart=/usr/local/docker/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
KillMode=process
[Install]
WantedBy=multi-user.target
chmod +x /usr/lib/systemd/system/docker.service #给脚本加可执行权限
systemctl daemon-reload #重新加载服务的配置文件
很多时候在挂载磁盘后不想用docker默认目录,可用 -g 修改目录到指定目录 (docker默认目录是/var/lib/docker,包括pull下来的镜像都在该目录下)
ExecStart修改为:ExecStart=/usr/bin/dockerd -g /hengha/docker
5、启动docker服务
systemctl start docker.service #启动docker服务
6、查看docker相关信息
docker version #显示Docker版本信息
docker info #显示docker信息详情
配置镜像加速
cat << EOF>> /etc/docker/daemon.json
{
"registry-mirrors": ["https://7xdlztz4.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
yum install gcc-c++ -y
yum update xfsprogs -y
vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.soc
标签:com,ce,systemctl,yum,usr,docker,安装,Docker,Docker01
From: https://www.cnblogs.com/lixunblogs/p/18167370