暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

docker部署

原创 幸福的小猪 2024-02-02
175

在线安装


在 CentOS 7 安装 docker 要求系统为 64 位、系统内核版本为 3.10 以上,可以使用以下命令查看

uname -r

使用 yum 安装 docker

yum install -y docker

启动 docker

systemctl start docker

查看 docker 状态

systemctl status docker

离线安装


可以先下载到本地,然后通过 ftp 工具上传到服务器上,或者在服务器上使用命令下载

wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz

解压

cp docker-18.06.3-ce.tgz /usr/bin/ cd /usr/bin tar -zxvf docker-18.06.3-ce.tgz

在/etc/systemd/system/目录下新增 docker.service 文件,内容如下,这样可以将 docker 注册为 service 服务

[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=127.0.0.1 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

此处的–insecure-registry=127.0.0.1(此处改成你私服 ip)设置是针对有搭建了自己私服 Harbor 时允许 docker 进行不安全的访问,否则访问将会被拒绝。

启动 docker

# 给docker.service文件添加执行权限 chmod +x /etc/systemd/system/docker.service # 重新加载配置文件(每次有修改docker.service文件时都要重新加载下) systemctl daemon-reload # 启动 systemctl start docker #设置开机启动 systemctl enable docker.service #查看docker服务状态 systemctl status docker

docker 无法下载任何东西的解决方法

修改 docker 镜像,一般默认镜像是国外的,可以修改为阿里云的

修改文件:sudo vi etc/docker/daemon.json 如下:

# 文件修改为: { "registry-mirrors": ["https://1r8ons4p.mirror.aliyuncs.com"] } # 重启 systemctl daemon-reload systemctl restart docker

编辑虚拟机文件

sudo vi /etc/sysctl.conf # 文件中增加一行 net.ipv4.ip_forward=1 # 重启服务 systemctl restart network

添加 dns,遇到问题最终的解决方案(很重要)

sudo vi /etc/resolv.conf # 在文件中增加两行(只增加不删除) nameserver 8.8.8.8 nameserver 8.8.4.4 # 重启docker systemctl restart docker

经过以上三个步骤,问题就解决了

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论