gpt4 book ai didi

docker - 您如何在Docker Compose中使用Docker构建秘诀?

转载 作者:行者123 更新时间:2023-12-02 19:55:02 26 4
gpt4 key购买 nike

使用docker build命令行,我可以按以下方式传递构建 secret

docker build \
--secret=id=gradle.properties,src=$HOME/.gradle/gradle.properties \
--build-arg project=template-ms \
.

然后在Dockerfile中使用它
# syntax = docker/dockerfile:1.0-experimental

FROM gradle:jdk12 AS build
COPY *.gradle .
RUN --mount=type=secret,target=/home/gradle/gradle.properties,id=gradle.properties gradle dependencies
COPY src/ src/
RUN --mount=type=secret,target=/home/gradle/gradle.properties,id=gradle.properties gradle build
RUN ls -lR build
FROM alpine AS unpacker
ARG project
COPY --from=build /home/gradle/build/libs/${project}.jar /tmp
RUN mkdir -p /opt/ms && unzip -q /tmp/${project}.jar -d /opt/ms && \
mv /opt/ms/BOOT-INF/lib /opt/lib
FROM openjdk:12
EXPOSE 8080
WORKDIR /opt/ms
USER nobody
CMD ["java", "-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=0.0.0.0:8000", "-Dnetworkaddress.cache.ttl=5", "org.springframework.boot.loader.JarLauncher"]
HEALTHCHECK --start-period=600s CMD curl --silent --output /dev/null http://localhost:8080/actuator/health
COPY --from=unpacker /opt/lib /opt/ms/BOOT-INF/lib
COPY --from=unpacker /opt/ms/ /opt/ms/

我想使用docker-compose进行构建,但在 docker-compose.yml reference中找不到如何传递 secret

这样开发人员只需要输入 docker-compose up

最佳答案

您可以使用环境或args将变量传递给docker-compose中的容器。
args:
- secret=id=gradle.properties,src=$HOME/.gradle/gradle.properties
environment:
- secret=id=gradle.properties,src=$HOME/.gradle/gradle.properties

关于docker - 您如何在Docker Compose中使用Docker构建秘诀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58597645/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com