Docker配置
1.安装docker
#!/bin/sh
set -e
# 在线安装脚本
# k3s 不建议安装swap 系统内存小的时候没有swap会卡死
if [ ! -f "/var/swap" ];then
echo "create swap"
dd if=/dev/zero of=/var/swap bs=1024 count=8192000
mkswap /var/swap
mkswap -f /var/swap
swapon /var/swap
echo "/var/swap swap swap defaults 0 0" >> /etc/fstab
fi
# 判断是否安装 docker
if [ `command -v docker` ];then
echo 'docker has installed'
else
echo 'install docker'
curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
yum -y install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# centos7 的内核经过 k3s 检查都有这个问题
grubby --args="user_namespace.enable=1" --update-kernel="$(grubby --default-kernel)"
fi
# 添加加速源
sudo mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors":["https://76y26nea.mirror.aliyuncs.com"],"insecure-registries":["116.204.83.21:8080"],"live-restore": true}
EOF
# 启动
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl enable docker
echo 'finish'
因为jenkins会使用80端口,因此harbor默认的80端口需要修改,此处修改为8080
2.开启 Docker RemoteAPI
vim /usr/lib/systemd/system/docker.service
#14 行 修改为
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
systemctl daemon-reload
systemctl restart docker
3.安装 DockerCompose
mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
3.安装 Harbor
前提条件 已安装docker-compose
- 解压harbor 离线包
tar -zxvf harbor-offline-installer-v1.9.3.tgz
- 修改 harbor.yml hostname配置
vim harbor.yml
- 执行安装
sh install.sh
4.配置 docker 连接私服
vim /etc/docker/daemon.json
# 修改insecure-registries 的IP
{"registry-mirrors":["https://76y26nea.mirror.aliyuncs.com"],"insecure-registries":["116.204.83.21:8080"],"live-restore": true}
构建部署
1.Harbor私服
- idea中配置harbor私服地址
<docker.registry>116.204.83.21:8080</docker.registry>
<docker.host>http://116.204.83.21:2375</docker.host>
<docker.namespace>library</docker.namespace>
<docker.username>admin</docker.username>
<docker.password>Harbor12345</docker.password>
2.maven构建镜像
- 方法一:命令行模式
# 构建哪个模块,就需要切换对应模块的 pom.xml 同级执行
mvn install docker:build
# 推送镜像到harbor私服
mvn docker:push
- 方法二:使用idea maven面板
3.初始化必备镜像
docker pull java:8-jre
docker pull pig4cloud/java:8-jre
# nacos必备
docker pull moxm/java:1.8-full
4.上传到Harbor中的镜像
5.点击某一个镜像,复制pull命令
docker pull 116.204.83.21:8080/library/youxin-upms-biz:5.1.0 -t youxin-upms
标签:Harbor,私服,harbor,构建,swap,var,docker
From: https://www.cnblogs.com/leepandar/p/17713366.html