问题描述
使用 docker build
命令行,我可以按如下所示传递构建密码
Using the docker build
command line I can pass in a build secret as follows
docker build \
--secret=id=gradle.properties,src=$HOME/.gradle/gradle.properties \
--build-arg project=template-ms \
.
然后在Dockerfile中使用它
Then use it in a 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参考如何传递秘密
.
I want to do a build using docker-compose, but I can't find in the docker-compose.yml reference how to pass the secret
.
这样,开发人员只需输入 docker-compose up
That way the developer just needs to type in docker-compose up
推荐答案
您可以使用环境或args将变量传递给docker-compose中的容器.
You can use environment or args to pass variables to container in docker-compose.
args:-secret = id = gradle.properties,src = $ HOME/.gradle/gradle.properties
环境:-secret = id = gradle.properties,src = $ HOME/.gradle/gradle.properties
这篇关于您如何在Docker Compose中使用Docker构建秘诀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!