...
Code Block | ||
---|---|---|
| ||
FROM golang:1.7 COPY . /go/src/github.com/microservices-demo/catalogue WORKDIR /go/src/github.com/microservices-demo/catalogue RUN go get -u github.com/FiloSottile/gvt RUN gvt restore && \ CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /app github.com/microservices-demo/catalogue/cmd/cataloguesvc FROM alpine:3.4 ENV SERVICE_USER=myuser \ SERVICE_UID=10001 \ SERVICE_GROUP=mygroup \ SERVICE_GID=10001 RUN addgroup -g ${SERVICE_GID} ${SERVICE_GROUP} && \ adduser -g "${SERVICE_NAME} user" -D -H -G ${SERVICE_GROUP} -s /sbin/nologin -u ${SERVICE_UID} ${SERVICE_USER} && \ apk add --update libcap WORKDIR / COPY --from=0 /app /app COPY images/ /images/ RUN chmod +x /app && \ chown -R ${SERVICE_USER}:${SERVICE_GROUP} /app /images && \ setcap 'cap_net_bind_service=+ep' /app USER ${SERVICE_USER} ARG BUILD_DATE ARG BUILD_VERSION ARG COMMIT LABEL org.label-schema.vendor="Weaveworks" \ org.label-schema.build-date="${BUILD_DATE}" \ org.label-schema.version="${BUILD_VERSION}" \ org.label-schema.name="Socks Shop: Catalogue" \ org.label-schema.description="REST API for Catalogue service" \ org.label-schema.url="https://github.com/microservices-demo/catalogue" \ org.label-schema.vcs-url="github.com:microservices-demo/catalogue.git" \ org.label-schema.vcs-ref="${COMMIT}" \ org.label-schema.schema-version="1.0" CMD ["/app", "-port=80"] EXPOSE 80 |
Infocode | ||
---|---|---|
| ||
FROM mysql:5.7
# ENV MYSQL_ROOT_PASSWORD DEFAULT_PASS
# ENV MYSQL_ALLOW_EMPTY_PASSWORD=true
# ENV MYSQL_DATABASE=socksdb
COPY ./data/dump.sql /docker-entrypoint-initdb.d/
|
Info | ||
---|---|---|
| ||
다단계 빌드 사용다단계 빌드를 사용하면
단일 Dockerfile 만 필요합니다. 별도의 빌드 스크립트가 필요하지 않습니다. Just Run:
최종 결과는 이전과 동일한 작은 제작 이미지이며, 복잡성이 현저히 줄어 듭니다. 중간 이미지를 작성할 필요가 없으며 로컬 시스템에 아티팩트를 전혀 추출 할 필요가 없습니다. 어떻게 작동합니까? 두 번째
Go SDK 및 중간 아티팩트는 남겨져 있으며 최종 이미지에 저장되지 않습니다. |
Info | ||
---|---|---|
| ||
version: '2' services: catalogue: build: context: . dockerfile: ./docker/catalogue/Dockerfile image: weaveworksdemos/catalogue hostname: catalogue restart: always cap_drop: - all cap_add: - NET_BIND_SERVICE read_only: true environment: - reschedule=on-node-failure ports: - "8080:80" catalogue-db: build: context: ./docker/catalogue-db/ image: weaveworksdemos/catalogue-db hostname: catalogue-db restart: always environment: - reschedule=on-node-failure - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} - MYSQL_ALLOW_EMPTY_PASSWORD=true - MYSQL_DATABASE=socksdb |
...