I have a Dockerfile with the following content
FROM eclipse-temurin:17-alpine
RUN apk update && apk add --no-cache curl gcompat
ENV REPO_USERNAME=username
ENV REPO_PASSWORD=password
# Create a directory for Puppeteer
RUN mkdir -p /puppeteer
RUN curl --user "$REPO_USERNAME:$REPO_PASSWORD" -o reqLoader-linux http://10.81.9.1/tools/puppeteer-v13/reqLoader-linux
RUN mv reqLoader-linux /puppeteer/reqLoader-linux
It works fine, as you see I use there username and password, I want to save those credentials in a secure place and be able to access them from this script.
I am running this Dockerfile using .sh script in git bash(win 11) This image will be created on the linux env in production and I want simple/minimal solution to achive this
I tryied to run docker secret create my_secret ./credentials
and in the credentials.json I have
{
"username" : "username",
"password" : "password"
}
In this case, I get
Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
should I init swarm and go that way? another possible solution I am reading now is compose file
the solution that I imagine should be an encrypted file in which stored the credentials and only docker can see it when running Dockerfile
I was able to solve the problem by doing the following steps
machine 10.81.9.1 login testusername password testpassword!
DOCKER_BUILDKIT=1 docker build --secret id=netrc,src=./.netrc -t $IMAGE:$TAG .
instead of the olddocker build . -t $IMAGE:$TAG
# syntax = docker/dockerfile:1.0-experimental
and then to download file using this commandRUN --mount=type=secret,id=netrc curl --netrc-file /run/secrets/netrc --output reqLoaderLinux http://10.81.9.1/tools/puppeteer-v13/reqLoader-linux
useful sources solution , about .netrc file