Communicate Gitlab and Gitlab Runner launched with Docker

Premise

I rent a virtual server with Sakura VPS and run Gitlab on that server. Gitlab was launched with docker-compose by referring to the official document GitLab Docker images. Also, there was a convenient image of nginx-proxy for SSL support. I tried to use it and fought hard, but trying to fly directly from nginx-proxy to the puma server without going through internal nginx did not work, and currently Gitlab alone is in the form of launching. .. Since it is launched by itself, refer to Gitlab SSL Configuration (lets-encrypt-integration) internally. I am getting and renewing my SSL certificate. All of these are set so that they can be retained on the local host side by specifying the volume of docker-compose.

This time, it is not about these startup methods, but about communication between Docker containers.

Operation of Gitlab Runner

Since I wanted to move CI with the operation of Gitlab, I decided to additionally operate Gitlab Runnner. The basic installation was done according to the official document Run GitLab Runner in a container. Since I was a beginner of Docker, I thought that communication between containers should be on the same network in Docker, so as usual, docker network create --driver = bridge --subnet = subnet specification --gateway = I created a network with the specified network name of the gateway, and started Gitlab and Gitlab Runner on the same network.

If you look up inter-container communication, it probably means ping between localhosts, and I see many articles that say, "You can communicate if you put them in the same Docker network." However, Http communication to Gitlab that is open to the outside is played by someone and curl: (7) Failed to connect to gitlab.example.com port 443: No route to host and curl It didn't even come back. It's embarrassing because I'm too new to Docker, but I was able to communicate between containers in this regard in a way that everyone might take for granted. I would like to leave that as a commandment.

Supplement In gitlab.example.com, DNS is suitable for the global IP of the host, and Curl etc. are returned without difficulty unless it is between containers.

solution

As a result, it seemed to be played due to the firewall on the host side. Therefore, I found that it is necessary to make settings so that the firewall can pass through the network used in the Docker network.

this time. The newly created Docker network specifies 172.31.0.0/16 as the subnet. You can check the network with docker network inspect network name.

Therefore, I added a firewall rule for this subnet, thinking that I should pass through the network of 172.31.0.0/16, but it didn't work. Here is an article saying that you should add a rule for 172.0.0.0/8 (Docker --No route to host I found host)), so when I tried it honestly, I was able to communicate safely. Now you can communicate between Gitlab and Gitlab Runner, and you can register Runner.

The commands you hit are summarized below. If the subnet is 192.168. ~~, I think it would be nice to be able to break through that firewall. (I'm not sure)

sudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family=ipv4 source address=172.0.0.0/8 accept'
sudo firewall-cmd --permanent --zone=public --add-masquerade
sudo firewall-cmd --reload
sudo less /etc/firewalld/zones/public.xml

>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <masquerade/>
  <!--Good if this is added-->
  <rule family="ipv4">
    <source address="172.0.0.0/8"/>
    <accept/>
  </rule>
</zone>

Finally

I'm sorry for the dirty sentences that I'm not used to writing Qiita. Docker is too convenient and I try to do simple tests with Docker. Although I can use Gitlab Runner, I still haven't studied CI yet, so I would like to devote myself to it.

Please point out if something is wrong.

Recommended Posts

Communicate Gitlab and Gitlab Runner launched with Docker
Set up GitLab with docker
Hello World with Docker and C
Microservices With Docker and Cloud Performance
Building Rails 6 and PostgreSQL environment with Docker
Launched Redmine with Docker on Raspberry Pi 3
Make a daily build of the TOPPERS kernel with Gitlab and Docker
Experience .NET 5 with Docker and Visual Studio Code
Create jupyter notebook with Docker and run ruby
Prepare a scraping environment with Docker and Java
Build Elastic Stack with Docker and analyze IIS logs
Access and debug Circle CI Docker container with ssh
Run Android instrumentation unit tests with GitLab CI + Docker
(For myself) Build gitlab with ubuntu18.04 + docker for home (Note)
Run Mosquitto with Docker and try WebSocket communication with MQTT
Build WordPress environment with Docker (Local) and AWS (Production)
Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop
CI/CD pipeline and Docker
Docker installation and initialization
Docker terms and commands
Launch MariaDB with Docker
Rails deploy with Docker
Run Pico with docker
Explode Docker with WSL2
Use Puphpeteer with Docker
Operate Emby with Docker
Try WildFly with Docker
Use ngrok with Docker
Run Payara with Docker
[Docker] Connection with MySQL
Php settings with Docker
Getting Started with Docker
Disposable PHP with Docker
Install Composer with Docker
Network device config management automation verification with oxidized and gitlab
Make Docker confusing with Pokemon and make it easier to attach
Easy environment construction of MySQL and Redis with Docker and Alfred
Build Docker Image lightweight and fast with CodeBuild with Santa Banner
Build a Node-RED environment with Docker to move and understand
Time is wrong with the application launched on the Docker container
Elasticsearch> Build with docker, get Twitter information and visualize with Kibana
Create Rails5 and postgresql environment with Docker and make pgadmin available
Java: Start WAS with Docker and deploy your own application
Write DiscordBot to Spreadsheets Write in Ruby and run with Docker