CentOS 部署 docter+docker-compose
环境
| 系统 |
资源 |
网络 |
部署环境 |
| CentOS7-1804 |
4C+8G+100G |
NAT |
VM16 |
基础环境配置
网卡
vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.50
PREFIX=24
GATEWAY=192.168.100.10
DNS1=8.8.8.8
DNS2=114.114.114.114
systemctl restart network
ping -c 2 www.baidu
关闭firewalld,selinux
systemctl disable firewalld
systemctl stop firewalld
vi /etc/selinux/config
SELINUX=disabled
setenforce 0
getenforce
设置主机名
hostnamectl set-hostname docker
bash
备份,下载yum源
mkdir /yum.repo.backup
cp -rf /etc/yum.repos.d/* /yum.repo.backup/
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce-staging.repo
yum clean all
yum makecache
yum repolist
配置时间同步
yum -y install chrony
vi /etc/chrony.conf
server ntp1.aliyun.com iburst
systemctl restart chronyd
systemctl enable chronyd
chronyc sources
更新系统
uname -r
yum -y update
reboot
#常用工具
yum update
yum -y install net-tools vim wget telnet tree lsof bind-utils
下载docker
yum install -y yum-utils device-mapper-persistent-data lvm2
#系统工具
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
#卸载旧版本
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#配置所需库,官方库
#阿里源 sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#或者清华源 sudo yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
#安装最新版docker
systemctl start docker
systemctl enable docker
测试
ps -ef | grep docker
yum -y net-tools
netstat -lntp | grep docker
docker --version
docker run hello-world
额外配置
#https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
#"https://bsfdwtme.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"https://mirrors.huaweicloud.com",
"https://ccr.ccs.tencentyun.com",
"https://hub-mirror.c.163.com",
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
#systemctl reset-failed docker.service
#清除失败次数
sudo docker info
#查看配置是否成功
docker-compose安装下载(网络)
curl -L https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
#curl -SL https://ghproxy.com/https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
#wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64
#可能会遇到需要证书的情况,可以使用--no-check-certificate跳过证书检查
#使用代理:如果你使用了网络代理,尝试使用 --proxy 参数指定代理服务器。例如,wget --proxy=http://proxy-server:port -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64。
#使用非加密的连接:如果你不需要通过加密连接下载,可以尝试使用 http 协议替代 https 协议进行下载。请注意,这样会降低数据传输的安全性,请在安全环境中慎用。例如,wget -O /usr/local/bin/docker-compose http://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64。
#wget -O /usr/local/bin/docker-compose https://ghproxy.com/https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
curl -L "https://mirrors.aliyun.com/docker-toolbox/linux/compose/1.9.0/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version