Dockerfile with secrets
The most secure way to use secrets in a Dockerfile is to use the --secret
flag in the docker build
command. This way, the secret is not stored in the image, and it is not visible in the Dockerfile.
A common use case in Python world is to install packages from a private PyPI repository in a Dockerfile. Suppose during the CICD pipeline, there's an environment variable called PIP_INDEX_URL
where holds this private PyPI credentials.
Check the official Build secrets doc.