例一
前端示例
一段打包
FROM nginx:1.16.1
MAINTAINER wanghaima
# 复制配置文件
COPY scripts/nginx/api_proxy.conf /etc/nginx/conf.d/api_proxy.conf
# 复制宿主机当前路径上的roadmap目录,到容器/usr/share/nginx/目录中,并改名为html
COPY roadmap /usr/share/nginx/html
EXPOSE 88
# 防止主程序退出后,nginx容器也就退出了
CMD ["nginx", "-g", "daemon off;"]
例二
一段打包
后端示例
FROM alpine:latest
ENV TZ Asia/Shanghai
WORKDIR /app
RUN mkdir /app/tmp
COPY ./admin_api /app/
COPY ./config /app/config
COPY ./static /app/static
COPY ./cmd/migrate/migration /app/cmd/migrate/migration
RUN chmod +x /app/admin_api
EXPOSE 8081
ENTRYPOINT ["/app/admin_api", "server"]
CMD ["-c=config/settings.dev.k8s.yml"]
例三
一段打包
后端示例
FROM alpine:latest
#FROM alpine:3.7
MAINTAINER haimait
RUN sed -i 's/https/http/' /etc/apk/repositories
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk update
RUN cat /etc/apk/repositories
RUN apk --no-cache update && \
apk --no-cache add tzdata
ENV TZ Asia/Shanghai
WORKDIR /app
RUN mkdir /app/log
COPY ./script_task /app/
COPY ./config /app/config
RUN chmod +x /app/script_task
EXPOSE 9000
ENTRYPOINT ["/app/script_task"]
CMD ["config/settings.yaml"]
例四:
二段打包
后端示例
vim Dockerfile
内容
FROM golang:1.19-alpine AS builder
MAINTAINER haimait
WORKDIR /work
RUN go env -w GOPROXY=https://goproxy.cn,direct && go env -w GO111MODULE=on && go env -w CGO_ENABLED=0
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o go-admin main.go
FROM alpine:latest
# change timezone
RUN sed -i 's/https/http/' /etc/apk/repositories
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk update
RUN cat /etc/apk/repositories
RUN apk --no-cache update && apk --no-cache add tzdata
# https://hub.docker.com/r/cypress/browsers
#FROM cypress/browsers
#FROM 10.10.11.145:8082/cypress/browsers_libreoffice7.1
ENV TZ Asia/Shanghai
WORKDIR /go-admin-api
COPY --from=builder /work/go-admin ./
COPY --from=builder /work/config ./config
COPY --from=builder /work/static ./static
COPY --from=builder /work/cmd/migrate/migration /app/cmd/migrate/migration
RUN mkdir /app/tmp
#COPY --from=builder /work/temp ./temp
EXPOSE 8000
# CMD ["./go-admin","server","-c", "config/settings.dev.yml"]
## 使用这种,启动容器时可以使用 command 修改 CMD 的参数
ENTRYPOINT ["/go-admin-api/512cert_admin_api", "server"]
CMD ["-c=config/settings.dev.yml"]
作者:海马 创建时间:2023-05-07 07:30
最后编辑:海马 更新时间:2024-08-03 21:41
最后编辑:海马 更新时间:2024-08-03 21:41