The process of building and configuring the Git environment in Docker

The process of building and configuring the Git environment in Docker

Configure Git environment in Docker

At work, I encountered a scenario where I needed to operate a GitLab repository in a Docker environment, so I needed to set up the Git environment in Docker in advance.

Since the operation of Git repository in Docker is fully automated, it is necessary to pull the repository and submit operations without password. I use SSH to perform password-free operations here.

So the first thing is to configure SSH, and the second is to configure the Docker environment.

Configure SSH Key

First generate SSH key:

ssh-agent
eval $(ssh-agent -s)
ssh-keygen -o -t rsa -b 4096 -C "{username}"
ssh-add ~/.ssh/id_rsa //Add to .bashrc

Go to the GitLab page and log in, then select Settings.

insert image description here
insert image description here
insert image description here

Select SSH Keys in the left navigation bar.

Copy the previously generated public key id_rsa.pub file (the file is in ~/.ssh/id_rsa.pub ) to this area:

insert image description here

Then click Add key:

insert image description here

In this way, the SSH public key is bound to the GitLab user, and the user can be used to perform password-free operations on the Git repository in the future.

Configure Docker environment

First, copy the private key to the same directory as the Dockerfile (assuming there is a Dockerfile in the project), and then configure the Dockerfile.

# configure ssh environment for gitlab
RUN mkdir -p /root/.ssh
COPY id_rsa /root/.ssh/
RUN echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config \
    && echo "UserKnownHostsFile /dev/null" >> /etc/ssh/ssh_config
RUN git config --global user.email "[email protected]" \ 
    && git config --global user.name "username"

Just insert this code into it. For user.email and user.name, use the account number that configured GitLab SSH Key before.

At this point, you can operate the Git repository in Docker without password.

Possible Errors

If the following errors still exist:

insert image description here

This indicates id_rsa 權限問題,通過在Dockerfile 中加入

RUN chown 1000:1000 /root/.ssh/id_rsa

The problem is solved.

This concludes this article about the process of setting up and configuring the Git environment in Docker. For more information about configuring the Git environment with Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed tutorial on building a continuous integration delivery environment based on Docker+K8S+GitLab/SVN+Jenkins+Harbor
  • Methods and steps for deploying GitLab environment based on Docker
  • Use Docker to build a Git image using the clone repository
  • How to quickly deploy Gitlab using Docker
  • Docker-compose one-click deployment of gitlab Chinese version method steps
  • Centos7 uses docker to build gitlab server
  • Detailed explanation of using docker to build gitlab

<<:  MySQL series 9 MySQL query cache and index

>>:  A brief analysis of the four import methods and priorities in CSS

Recommend

An article to teach you HTML

If you are not committed to becoming an artist, t...

MySQL multi-table join introductory tutorial

Connections can be used to query, update, and est...

33 of the best free English fonts shared

ChunkFive Free Typefamily Cuprum JAH I Free font Y...

How to change the system language of centos7 to simplified Chinese

illustrate When you install the system yourself, ...

25 Ways and Tips to Increase Web Page Loading Speed

Introduction <br />Not everyone has access t...

Vuex implements a simple shopping cart

This article example shares the specific code of ...

Linux nohup to run programs in the background and view them (nohup and &)

1. Background execution Generally, programs on Li...

Detailed explanation of the difference between Vue life cycle

Life cycle classification Each component of vue i...

mysql show simple operation example

This article describes the mysql show operation w...

Meta tags in simple terms

The META tag, commonly referred to as the tag, is...

Summary of MySQL injection bypass filtering techniques

First, let’s look at the GIF operation: Case 1: S...

How to verify whether MySQL is installed successfully

After MySQL is installed, you can verify whether ...