主要記錄一下過程新的
docker環境
參考 菜鳥教程(https://www.runoob.com/docker/centos-docker-install.html)
安裝所需的軟件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存儲驅動程序需要 device-mapper-persistent-data 和 lvm2。
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
使用以下命令來設置穩定的倉庫
# 官方鏡像
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
docker-compose環境
參考 菜鳥教程(https://www.runoob.com/docker/docker-compose.html)
安裝包發布地址: https://github.com/docker/compose/releases
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 1.28.2 是版本號,可以去 https://github.com/docker/compose/releases 找最新的版本號
docker-compose.yml
version: '3.7'
networks:
dep:
services:
# docker 私服
registry:
image: registry:2
container_name: registry
restart: always
networks:
dep:
aliases:
- registry
ports:
- "5000:5000"
volumes:
- /var/lib/registry:/var/lib/registry
# jenkins 部署
jenkins:
image: jenkins/jenkins:lts
container_name: jenkins
restart: always
networks:
dep:
aliases:
- jenkins
ports:
- "8080:8080"
- "50000:50000"
volumes:
- /etc/localtime:/etc/localtime # 時區
- /var/jenkins_home:/var/jenkins_home # 這個地方需要注意給jenkins_home權限,不然無法啟動成功:執行:sudo chown -R 1000 jenkins_home
- /usr/bin/docker:/usr/bin/docker
- /var/run/docker.sock:/var/run/docker.sock
- /usr/lib64/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
user: root # 解決容器中執行docker權限問題
# 用來測試自動化構建的vue工程
vue3play:
image: 127.0.0.1:5000/vue3-play:latest
container_name: vue3play
restart: always
networks:
dep:
aliases:
- vue3play
jenkins docker命令問題,以及權限問題
參考:https://www.isolves.com/it/cxkf/rongqi/2020-11-06/32886.html
構建命令
選擇自由風格:執行shell
pwd
docker build -t vue3-play .
docker tag vue3-play:latest 127.0.0.1:5000/vue3-play:latest
docker push 127.0.0.1:5000/vue3-play
ssh遠程執行命令
cd /home/ly # 你的docker-compose.yml文件路徑
sh restart-dc.sh
附上 restart-dc.sh
只是簡單的啟動docker-compose
,然后清理none的image
#!/bin/bash
echo "--start docker-compose up -d"
cd /home/ly
docker-compose up -d
echo "--start rmi none image"
docker rmi $(docker images | grep "none" | awk '{print $3}')
vue3-play 參考來源于 vue-cli
Dockerfile
FROM node:14.15.4-alpine3.10
COPY ./ /app
WORKDIR /app
RUN npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
RUN npm install --registry=https://registry.npm.taobao.org && npm run build
FROM nginx
RUN mkdir /app
COPY --from=0 /app/dist /app
COPY nginx.conf /etc/nginx/nginx.conf
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
github webhook
通過github給jenkins觸發構建任務
參考:https://blog.csdn.net/qq_38588845/article/details/112404336
- 先配置github密鑰
- jenkins添加github服務器,用密鑰鏈接github
- github添加jenkins鏈接:
http(s)://jenkins的地址/github-webhook/
- 構建項目中勾選
GitHub hook trigger for GITScm polling