How to pass password in the Docker run

Asked

Viewed 1,219 times

0

I have in my Docker file a command that I clone using git, I am using the:
ENV USUÁRIO \ SENHA

Over there (inside the dockerfile) I’m calling these ENV:

RUN git clone git clone https://$USUARIO_BITBUCKET:[email protected]/.../...

only that for me this is redundant, since I want to pass this password and login in the run of the image like:

docker run -e USUARIO=123 -e SENHA=123 IMAGEM COMANDO

1 answer

0


As you did, you need to modify Dockerfile at all times to change the value of the USER and PASSWORD variables. Also need to rebuild the image with Docker build -t ..

Obviously, it is not very practical and is also not very feasible if you want to distribute this image via the Docker Hub so that the user only needs to inform his password through the command Docker run -e.

Before, remember that variables passed through the option -and or command ENV in Dockerfile have seen environment variables in the shell. So you can have a script file, for example, run sh.. He can be more or less like this:

#!/bin/bash
git clone git clone https://"$USUARIO_BITBUCKET":"$SENHA_BITBUCKET"@bitbucket.org/.../...

In your Dockerfile, which you will use to create your image, modify to something like this:

FROM ubuntu
ADD run.sh run.sh
RUN chmod +x run.sh
CMD ./run.sh

When you run this container with the command below, it will use the environment variables passed in the command run.

docker run --name teste -ti -e USUARIO_BITBUCKET=123 -e SENHA_BITBUCKET=123 nomeimagem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.