CentOS快速配置网络&&Docker快速部署
- CentOS裸机Docker部署
- 1.联通外网
- 2.配置CentOS镜像源
- 3.安装Docker
- 4.启动Docker
- 5.CentOS7安装DockerCompose
- Bug合集
- ERROR [internal] load metadata for docker.io/library/java:8-alpine
- Error: Could not find or load main class com.hitices.storage.ApplicationMain
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
因审核不过,省去安装步骤
chmod +x docker-compose
chmod +x /usr/local/bin/docker-compose
绿了就成功了(这里记得检查一下大小,有时候装完大小为0,莫名其妙)
chmod +x /usr/local/bin/docker-compose
Base自动补全命令:
因审核不过,省去安装步骤
如果这里出现错误,需要修改自己的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://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
Error: Could not find or load main class com.hitices.storage.ApplicationMain
运行容器时提示无法访问页面
docker logs container_name
提示Error: Could not find or load main class com.hitices.storage.ApplicationMain
之前在Windows上能跑,怀疑是环境出问题,应该是maven没配置好,没清理用了过时配置
没有mvn先安装yum install maven -y
参考文章
mvn clean
mvn package
后再build镜像
可以看到容器跑起来了
在Windows上访问,也成功获取到了(192.168.235.132是我的虚拟机ip地址)
ports:
- "10100:8080"
需要注意docker配置中的8080内端口和application.yaml的8080是对应的,10100是对外开放端口,所以这里访问192.168.235.132:10100