How to create a Docker image using a github project but to download it into the Docker with the clone using ssh key

Asked

Viewed 176 times

0

FROM python:3.6.7
LABEL maintainer="RENAN SACCA"
EXPOSE 8000

RUN git clone [email protected]:Renan-Sacca/projeto-contabilidade.git
WORKDIR teste-docker
RUN pip3 install -r requirements.txt

CMD ["python3", "main.py"]

my pc key is already on github but how do I use it inside the Docker constructor ?

2 answers

0

I believe you have two approaches here:

  1. Copy ssh keys into the container (as suggested by Caio Augusto Papa) still in Dockerfile doing something like

    COPY path/local path/no/container
    

For example, based on an image of Ubuntu, it would look something like

COPY ~/.ssh/SUA-CHAVE ~/.ssh/CHAVE-NO-CONTAINER

The problem I see with this approach is that this layer will stay forever in the history of the image, that is, everyone can have access to your ssh key running something like:

sudo docker history [sua-imagem:versão]
  1. Use the Docker Secrets that was done to pass this type of information so that it does not stay in the history layer. To adopt this approach, it will be necessary to enable the Docker build experimental. The two processes are very quiet to do just by following the documentation.

In this case, you will do a Dockerfile line with the "RUN --mount" command before copying the gitlab repository and, at the "Docker build" command, you will pass the key with the "-secret" flag".

I hope I’ve helped.

0

Whoops?

One way to do it is: Insert a step to copy the file from your machine into the container before making the clone.

Example:

COPY arquivo.txt diretório

Hug

Browser other questions tagged

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