CentOS快速配置网络&&Docker快速部署
- CentOS裸机Docker部署
- Bug合集
-
- [ERROR [internal] load metadata for docker.io/library/java:8-alpine](#ERROR [internal] load metadata for docker.io/library/java:8-alpine)
CentOS裸机Docker部署
1.联通外网
vi /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network
ip addr
ping www.baidu.com
2.配置CentOS镜像源
进入/etc/yum.repos.d目录下找到 CentOS-Base.repo
cd /etc/yum.repos.d
cp CentOS-Base.repo CentOS-Base.repo.backup
vi CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - Aliyun
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
3.安装Docker
首先需要大家虚拟机联网,安装yum工具
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2 --skip-broken
然后更新本地镜像源:
# 设置docker镜像源
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
yum makecache fast
然后输入命令:
yum install -y docker-ce
docker-ce为社区免费版本。稍等片刻,docker即可安装成功。
4.启动Docker
Docker应用需要用到各种端口,逐一去修改防火墙设置。非常麻烦,因此建议大家直接关闭防火墙!
启动docker前,一定要关闭防火墙后!!
启动docker前,一定要关闭防火墙后!!
启动docker前,一定要关闭防火墙后!!
# 关闭
systemctl stop firewalld
# 禁止开机启动防火墙
systemctl disable firewalld
通过命令启动docker:
systemctl start docker # 启动docker服务
systemctl stop docker # 停止docker服务
systemctl restart docker # 重启docker服务
通过命令启动docker:
docker -v
5.CentOS7安装DockerCompose
curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x docker-compose
chmod +x /usr/local/bin/docker-compose
绿了就成功了(这里记得检查一下大小,有时候装完大小为0,莫名其妙)
chmod +x /usr/local/bin/docker-compose
Base自动补全命令:
# 补全命令
curl -L https://raw.githubusercontent.com/docker/compose/1.29.1/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
如果这里出现错误,需要修改自己的hosts文件:
echo "199.232.68.133 raw.githubusercontent.com" >> /etc/hosts
docker-compose version
安装成功
Bug合集
ERROR [internal] load metadata for docker.io/library/java:8-alpine
Docker build镜像的时候报的错
应该是引入基础环境失败了,要换镜像源
vi /etc/docker/daemon.json
{
"max-concurrent-downloads": 10,
"max-concurrent-uploads": 5,
"default-shm-size": "1G",
"debug": true,
"experimental": false,
"registry-mirrors":[
"https://x9r52uz5.mirror.aliyuncs.com",
"https://dockerhub.icu",
"https://docker.chenby.cn",
"https://docker.1panel.live",
"https://docker.awsl9527.cn",
"https://docker.anyhub.us.kg",
"https://dhub.kubesre.xyz"
],
"insecure-registries": [
"registry.me:5000",
"http://docker.mirrors.ustc.edu.cn",
"https://k8s.gcr.io",
"https://github-releases.githubusercontent.com",
"https://registry-1.docker.io",
"decs.com"
],
"exec-opts": [
"native.cgroupdriver=systemd"
]
}
systemctl daemon-reload
systemctl restart docker
duocker build成功
docker build -t name:version .
docker images