Clone git repository with Docker
There are many ways to use Git with Docker, but this guide focuses on using SSH Deploy keys to clone a repository from GitLab or GitHub. as easily as possible.
I know there are many ways to do this, but I want to show you a simple way to do it.
Deploy keys
Deploy keys are used to give read-only access to a repository. Generate an entirely new SSH key pair for the deployment:
This command will generate a new SSH key pair without passphrase. Then you have to add the public key to the GitLab or GitHub
After adding the public key to the repository, you can test the connection:
Dockerfile
Create a Dockerfile
with the following content:
Let’s have a repository git@gitlab.com:your/app.git
them your entrypoint
file should look like this:
We can easily build git
container using the compose.yml
file:
Run the following command to build the image and start the container:
Your repository will be cloned to the source
folder.