Passing secrets when building Docker images

When building a Docker image I need to install an R package that we have in one of our private Bitbucket repos.

While testing, I have been setting the user and pwd as env variables so that I can execute remotes::install_bitbucket("org/repo"). An example:

FROM rocker/r-ver:4.2.1


RUN R -e "install.packages('remotes')"
RUN R -e "remotes::install_bitbucket('myorg/myrepo')"

Now I want to push this to Docker Hub, I need a more secure way of providing secrets in the build step.

Based on some research that I've done, I've removed the BITBUCKET_PASSWORD env from the Dockerfile, and am using the following command to try and build the image, but it's not working:

DOCKER_BUILDKIT=1 docker build --secret id=BITBUCKET_PASSWORD,src=path/to/file/test.txt -t test .

I get the error "Failed to install 'unknown package' from Bitbucket".

Do I need to modify the install_bitbucket function to be something like install_bitbucket("org/repo", password = BITBUCKET_PASSWORD)? I've tried variations on that as well but they don't work...

Any pointers on what I might be doing wrong are appreciated!

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.