Consider this Dockerfile:
FROM openjdk:17
COPY . .
EXPOSE 8999
RUN ./gradlew build
CMD java -jar -Dspring.profiles.active=local build/libs/example.jar
I can build this without problems with:
docker build -t example-service .
and run it with
docker run -p 8999 -d example-service
when I have a gradle.properties
file in the root folder (where I do COPY . .
) with the following content:
artifactoryUsername=user1
artifactoryPassword=password1
This works because I have the following snippet in my build.gradle
:
...
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repository.aspose.com/repo/' }
maven {
url 'https://my-url/artifactory/example-maven/'
credentials {
username artifactoryUsername
password artifactoryPassword
}
}
}
...
However, I don’t want to copy the gradle.properties
with secret information into the container.
(How) can I use docker build
‘s --secret
-option to do that? Or would you recommend something else?