Docker——下载与安装
① 在/usr/lib/systemd/system/目录下,创建docker.service文件。② 编辑docker.service文件。
·
文章目录
一、有网的情况下安装
# 首先,使用yum remove docker* 移除之前安装的docker
yum remove docker*
# 配置yum源
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 下面这个命令是将软件包信息提前在本地缓存一份,用来提高搜索安装软件的速度
sudo yum makecache fast
# 安装docker
sudo yum install -y docker-ce docker-ce-cli containerd.io
# 启动Docker服务
systemctl start docker
# 设置开机自动启动
systemctl enable docker
# 测试
docker run hello-world
# 卸载的命令
sudo yum remove docker-ce docker-ce-cli containerd.io
# 软件卸载后,Docker默认的工作路径是/var/lib/docker 需要执行rm命令把这个工作路径删除
rm -rf /var/lib/docker
# 阿里云镜像加速配置
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://g090nq5l.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
二、无网络环境下安装docker
1、下载符合操作系统的docker版本
2、解压到指定目录下
tar -zxvf docker-23.0.1.tgz
3、解压的docker文件夹全部移动至/usr/bin目录
cp -p docker/* /usr/bin
4、将docker注册为系统服务
① 在/usr/lib/systemd/system/目录下,创建docker.service文件
vim /etc/systemd/system/docker.service
② 编辑docker.service文件
注:以下内容中 --insecure-registry=192.168.3.10 此处改为你自己服务器ip。
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=192.168.3.10
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
5、重启生效
重启守护进程
# 给予权限
chmod 777 /etc/systemd/system/docker.service
# 重启守护进程
systemctl daemon-reload
# 启动docker
systemctl start docker
# 查看docker状态
systemctl status docker
# 设置开机自启动
systemctl enable docker
更多推荐
已为社区贡献1条内容
所有评论(0)