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

HTML implements the function of detecting input completion

Use "onInput(event)" to detect whether ...

Vue imitates ElementUI's form example code

Implementation requirements The form imitating El...

How to upload projects to Code Cloud in Linux system

Create a new project test1 on Code Cloud Enter th...

MySQL horizontal and vertical table conversion operation implementation method

This article uses examples to illustrate how to i...

Detailed explanation of mysql permissions and indexes

mysql permissions and indexes The highest user of...

MySQL DML statement summary

DML operations refer to operations on table recor...

CSS3 animation – steps function explained

When I was looking at some CSS3 animation source ...

A Preliminary Study on Vue Unit Testing

Table of contents Preface Why introduce unit test...

Solution to the root password login problem in MySQL 5.7

After I found that the previous article solved th...

How to use cc.follow for camera tracking in CocosCreator

Cocos Creator version: 2.3.4 Demo download: https...

Alibaba Cloud ESC Server Docker Deployment of Single Node Mysql

1. Download the accelerated version of msyql dock...

Detailed process of decompressing and installing mysql5.7.17 zip

1. Download address https://dev.mysql.com/downloa...

HTML table tag tutorial (24): horizontal alignment attribute of the row ALIGN

In the horizontal direction, you can set the row ...

Implementing carousel effects with JavaScript

This article shares the specific code for JavaScr...