571
docker常用技巧
乐果 发表于 2022 年 12 月 11 日 标签:Docker
镜像打包
** Dockerfile ** 文件编写
案例:
# 编译arm盒子镜像
FROM --platform=linux/arm64/v8 golang:1.18-alpine3.15 as builder
WORKDIR /usr/src/app
COPY . .
ENV GOPROXY https://goproxy.cn
ENV CGO_ENABLED 0
RUN go mod tidy
RUN CGO_ENABLED=1 go build -v -o /usr/local/bin/app
FROM --platform=linux/arm64/v8 alpine:3.15.4
WORKDIR /data
RUN mkdir "config"; \
mkdir "logs"; \
mkdir "resource"; \
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories; \
apk update && apk upgrade && apk add vim && apk add --no-cache tzdata; \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime; \
echo "Asia/Shanghai" > /etc/timezone; \
rm -rf /var/cache/apk/*
COPY --from=builder /usr/local/bin/app /data
COPY --from=builder /usr/src/app/config/config.toml /data/config
ENTRYPOINT ["./app", "-c", "/data/config/config.toml"]
构建镜像 并推送至仓库
案例:
docker buildx build --push --platform linux/arm64/v8 -t hub.wesais.cn/edge/monibuca-arm-v8:v3.0 -f DockerfileArmV8 .
实例构建与运行
docker run -d --name go-blog \
--restart=always \
-p 18081:8080 \
-v /data/go-blog/data:/data/data \
hub.wesais.cn/edge/go-blog-arm:v.22.1210.01 \
-server 0.0.0.0:8080
容器实例编排
** docker-compose.yml **文件编写
案例:
version: "3"
services:
web:
container_name: openresty
image: openresty/openresty:alpine
restart: always
network_mode: host
volumes:
- ./openresty/conf.d:/etc/nginx/conf.d:ro
- ./openresty/www-data:/data/www-data
npc:
container_name: npc
image: ffdfgdfg/npc
restart: always
network_mode: host
entrypoint: /npc
command: -server=${sub_domain}.edge.papa.com.cn:8024 -vkey=${npc_key} -type=tcp
frpc:
container_name: frpc
image: snowdreamtech/frpc:0.44.0
restart: always
network_mode: host
environment:
- TZ=Asia/Shanghai
entrypoint: /usr/bin/frpc
command: http -s 116.62.203.20:7000 -t ed2c4592529 -l 8080 -n ${sub_domain}.edge.papa.com.cn --sd ${sub_domain}
hik:
container_name: hikSearch
image: hub.wesais.cn/edge/hiksearch-arm-v8:v3.1.8
restart: always
network_mode: host
m7s:
container_name: m7s
image: hub.wesais.cn/edge/monibuca-arm-v8:v22.0831
restart: always
network_mode: bridge
ports:
- "9090:8080"
- "1935:1935"
- "5060:5060"
- "5061:5061"
- "58200:58200/udp"
volumes:
- ./m7s/config:/data/config
- ./m7s/logs:/data/logs
- ./m7s/resource:/data/resource
dhproxy:
container_name: dhproxy
image: hub.wesais.cn/edge/dhproxy-arm-v8:v22.0906
restart: always
network_mode: bridge
volumes:
- ./dhproxy/config/conf.ini:/data/conf.ini
基于docker-compose.yml,构建容器实例
案例:
sub_domain=$subDomain npc_key=$npcKey docker compose up -d
乐果 发表于 2022 年 12 月 11 日 标签:Docker