docker-compose http curl 实现 自动化部署
使用 m2 开启 orbstack 的的 docker 远程 API (docker/damon.json)
{
"hosts": [
"tcp://0.0.0.0:2375",
"unix:///var/run/docker.sock"
],
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://ung2thfc.mirror.aliyuncs.com",
"https://registry.docker-cn.com"
],
"ipv6": false
}
docker for mac socket 默认路径
验证效果
telnet localhost 2375
拉取有个镜像 类似 docker pull
curl -XPOST "http://localhost:2375/v1.41/images/create?fromImage=alpine&tag=latest"
创建容器
curl -H "Content-Type: application/json" http://localhost:2375/containers/create?name=my_alpine -d '{
"Image": "alpine:latest",
"HostConfig": {
"NetworkMode": "host",
"Binds": [
"/tmp:/tmp"
]
},
"Cmd": [
"tail","-f","/dev/null"
]
}'
docker
启动容器
curl -XPOST http://localhost:2375/containers/my_alpine/start
上传文件到容器内部仅支持 tar格式的压缩包
curl -T input.tar -PUT "http://localhost:2375/v1.41/containers/my_alpine/archive?path=/app/proj"
远程执行命令 为两步,实例化命令,和执行实例化
- 实例化命令
curl -H "Content-Type: application/json" http://localhost:2375/containers/my_alpine/exec -d '{ "AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"DetachKeys": "ctrl-p,ctrl-q",
"Tty": false,
"Cmd": [
"sh","-c","cd /app/proj && sh ./push.sh"
],
"Env": [
"FOO=bar",
"BAZ=quux"
]
}'
执行实例化
curl --output - -XPOST -H "Content-Type: application/json" http://localhost:2375/exec/c1f78ddd7d7056383baf535f29f1f2d98a3ba0a701c2d478166c5eecc7b33ee3/start -d '{
"Detach": false,
"Tty": false
}'
- 命令只能被执行一次 否则会报错
下载文件 必须以.tar方式保存到本地,解压后才不会乱码(自动压缩)
curl -GET "http://localhost:2375/containers/my_alpine/archive?path=/app/proj/input.tar" -o output.tar
下载整个文件夹
curl -GET "http://localhost:2375/v1.41/containers/ubuntu_bolang/archive?path=/app/proj" -o out.zip
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17511460.html