代码拉取完成,页面将自动刷新
ConMan (Container Manager的缩写),取名困难症,这个名字还是GPT生成的
某些项目无法使用Kubernetes,又必须使用容器,为了方便快速从公司的Jenkins推送代码到项目上
在Jenkins构建好镜像后,使用curl给ConMan应用发送Post请求,请求中需要传递一个json,主要字段是容器名、镜像名、端口等。
构建镜像
docker build -t reg.harbor.com/docker-hub/conman:v0.1 .
或者使用我的镜像:
registry.cn-hangzhou.aliyuncs.com/image-acr/docker-hub:conman-v0.1
docker run -d --name conman --restart=always \
-p 5001:5000 \
registry.cn-hangzhou.aliyuncs.com/image-acr/docker-hub:conman-v0.1
curl -X POST http://192.168.1.1/update_container -H "Content-Type: application/json" -d '{
"token": "QP77ZUFXNO0PO9AWVPSYLS5WCXUSCA1NCL2BSLV8"
"dockerUrl": "192.168.3.24:2375",
"volumes": {
"/mnt/logs":"/data/logs",
"/mnt/conf":"/data/conf"
},
"containerName":"testNginx",
"networkMode": "bridge",
"image": "nginx:latest",
"env": {
"TZ": "Asia/Shanghai",
"MYSQL_ROOT_PASSWORD": "Tuf#8kgc"
},
"ports": {
"80/tcp": 80,
"9090/tcp":9090
},
"restart":"always"
}'
参数说明:
{
"token": "QP77ZUFXNO0PO9AWVPSYLS5WCXUSCA1NCL2BSLV8",
"dockerUrl": "192.168.3.24:2375", # Docker地址
"volumes": {
"/mnt/logs":"/data/logs", # 文件挂载,可选
"/mnt/conf":"/data/conf"
},
"containerName":"testNginx", # 容器名称,必选
"networkMode": "bridge", # 网络策略,可选
"image": "nginx:latest", # 镜像地址,必选
"env": { # 环境变量,可选
"TZ": "Asia/Shanghai",
"test": "123456zzz"
},
"ports": {
"80/tcp":80,
"9090/tcp":9090 # 端口映射,可选
},
"restart":"always" # 重启策略,可选
}
可在Docker的启动文件修改参数,让外部访问docker
vim /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500
[Install]
WantedBy=multi-user.target
需要重启docker
[root@anolis ~]# sudo systemctl daemon-reload
[root@anolis ~]# sudo systemctl restart docker.service
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。