How to pass password in docker run

0

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

Then in the command ( inside dockerfile ) I'm calling these ENV:

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

But for me this is redundant, since I want to pass this password and login to the image run of type:

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

    
asked by anonymous 22.06.2016 / 17:34

1 answer

0

As you've done, you need to modify Dockerfile at any time to change the value of the USER and PASSWORD variables. You also need to rebuild the image with docker build -t. .

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

First, remember that variables passed through the -e option or the ENV command in Dockerfile have seen environment variables in the shell. So you can have a script file, for example, run.sh . It may look something 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 it 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 run command.

docker run --name teste -ti -e USUARIO_BITBUCKET=123 -e SENHA_BITBUCKET=123 nomeimagem
    
22.06.2016 / 19:14