Docker introduction private notes review and summary 4 - harbor shutdown and startup

Posted by abhi201090 on Thu, 10 Mar 2022 16:03:17 +0100

Harbor is an enterprise level Docker private warehouse project. It is composed of multiple Docker Containers. The dependencies between containers are managed through Docker compose.

1. Installation

Please refer to the official document for installation: Harbor - Installation and Configuration Guide

Modify harbor When using YML, you should pay attention to:
(1) When using https, you need to generate your own certificate, and then in harbor Configure the path of the certificate in YML.

  • The client also needs to install the certificate you generated, otherwise an error will be reported. (so the certificate should be backed up)
  • See details Docker - Use self-signed certificates

(2)data_volume can be specified as / data/harbor, and then this folder will be backed up regularly. (or directly install a harbor on the new machine and use the warehouse copy function of harbor to make regular backups.)

(3) Enterprises may also need to configure ldap integration verification.

Then sudo/ install. SH install harbor (it seems that sudo must be used, because the owner of the generated configuration file is root and the permissions are set strictly.)

After installation, harbor.com will be started automatically

2. Set auto start

Check docker-compose.com in the harbor directory YML will find that all containers are configured with restart: always

version: '2.3'
services:
  log:
    image: goharbor/harbor-log:v1.8.1
    container_name: harbor-log
    restart: always
    dns_search: .
    # ......

  registry:
    image: goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1
    container_name: registry
    restart: always
    # ......

This means that all containers will restart automatically after accidental shutdown, such as docker restart or server restart. Of course, manual stop will not restart automatically.
However, after manually running docker compose up - D and restarting the server, I found that several container s did not restart automatically:

[ryan@ryan-pc ~]$ docker ps -a
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS                             PORTS                       NAMES
f30d802002a4        goharbor/nginx-photon:v1.8.1                        "nginx -g 'daemon of..."   13 hours ago        Exited (128) 27 minutes ago        0.0.0.0:80->80/tcp          nginx
21472ce8a993        goharbor/harbor-portal:v1.8.1                       "nginx -g 'daemon of..."   13 hours ago        Exited (128) 27 minutes ago        80/tcp                      harbor-portal
5d866bb17c58        goharbor/harbor-jobservice:v1.8.1                   "/harbor/start.sh"       13 hours ago        Exited (137) 26 minutes ago                                    harbor-jobservice
0cf0f93b5a87        goharbor/harbor-core:v1.8.1                         "/harbor/start.sh"       13 hours ago        Up 11 seconds (health: starting)                               harbor-core
cba280d9b945        goharbor/redis-photon:v1.8.1                        "docker-entrypoint.s..."   13 hours ago        Exited (137) 26 minutes ago        6379/tcp                    redis
473e46d1f746        goharbor/harbor-registryctl:v1.8.1                  "/harbor/start.sh"       13 hours ago        Up 11 seconds (health: starting)                               registryctl
51f105f1691d        goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1   "/entrypoint.sh /etc..."   13 hours ago        Exited (137) 26 minutes ago        5000/tcp                    registry
c41594ec7779        goharbor/harbor-db:v1.8.1                           "/entrypoint.sh post..."   13 hours ago        Up 11 seconds (health: starting)   5432/tcp                    harbor-db
713bd4961772        goharbor/harbor-log:v1.8.1                          "/bin/sh -c /usr/loc..."   13 hours ago        Up 11 seconds (health: starting)   127.0.0.1:1514->10514/tcp   harbor-log

You can see that the following five containers are in Exited state:
goharbor/nginx-photon:v1.8.1
goharbor/harbor-portal:v1.8.1
goharbor/harbor-jobservice:v1.8.1
goharbor/redis-photon:v1.8.1
goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1

The search found that someone mentioned this issue: https://github.com/goharbor/h...
So try to configure harbor as a systemd service and add the configuration file / usr / lib / systemd / system / harbor Service, as follows:

[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor

[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/local/bin/docker-compose -f {{ harbor_install_path }}/harbor/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f {{ harbor_install_path }}/harbor/docker-compose.yml down

[Install]
WantedBy=multi-user.target

Replace {{harbor_install_path}} with your own harbor installation path.
There is also the absolute path of docker compose. Please check it through which docker compose.

Then start the service and set it to start automatically:

sudo systemctl start harbor
sudo systemctl enable harbor

Now check out harbor Service:

● harbor.service - Harbor
   Loaded: loaded (/usr/lib/systemd/system/harbor.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-07-07 12:54:27 CST; 2min 4s ago
     Docs: http://github.com/vmware/harbor
 Main PID: 9734 (docker-compose)
    Tasks: 11 (limit: 4915)
   Memory: 35.7M
   CGroup: /system.slice/harbor.service
           └─9734 /usr/bin/python /usr/bin/docker-compose -f /home/ryan/harbor/docker-compose.yml up

7 December 7:54:30 ryan-pc docker-compose[9734]: [128B blob data]
7 July 12:54:31 ryan-pc docker-compose[9734]: [167B blob data]
7 July 12:54:31 ryan-pc docker-compose[9734]: registryctl    | WARNING: no logs are available with the 'syslog' log driver
7 July 12:54:31 ryan-pc docker-compose[9734]: registry       | WARNING: no logs are available with the 'syslog' log driver
7 July 12:54:31 ryan-pc docker-compose[9734]: harbor-db      | WARNING: no logs are available with the 'syslog' log driver
7 July 12:54:31 ryan-pc docker-compose[9734]: redis          | WARNING: no logs are available with the 'syslog' log driver
7 July 12:54:31 ryan-pc docker-compose[9734]: harbor-core    | WARNING: no logs are available with the 'syslog' log driver
7 July 12:54:31 ryan-pc docker-compose[9734]: harbor-jobservice | WARNING: no logs are available with the 'syslog' log driver
7 July 12:54:31 ryan-pc docker-compose[9734]: harbor-portal  | WARNING: no logs are available with the 'syslog' log driver
7 July 12:54:31 ryan-pc docker-compose[9734]: nginx          | WARNING: no logs are available with the 'syslog' log driver

Restart and look again. It is found that the harbor container group is finally up:

[ryan@ryan-pc ~]$ docker ps -a
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS                    PORTS                       NAMES
90943210e354        goharbor/nginx-photon:v1.8.1                        "nginx -g 'daemon of..."   37 seconds ago      Up 35 seconds (healthy)   0.0.0.0:80->80/tcp          nginx
bc70706d7b5f        goharbor/harbor-portal:v1.8.1                       "nginx -g 'daemon of..."   38 seconds ago      Up 36 seconds (healthy)   80/tcp                      harbor-portal
54e132bd1a10        goharbor/harbor-jobservice:v1.8.1                   "/harbor/start.sh"       38 seconds ago      Up 36 seconds                                         harbor-jobservice
28ada4a941ee        goharbor/harbor-core:v1.8.1                         "/harbor/start.sh"       39 seconds ago      Up 37 seconds (healthy)                               harbor-core
de44686f7e72        goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1   "/entrypoint.sh /etc..."   39 seconds ago      Up 38 seconds (healthy)   5000/tcp                    registry
e5efdae34c13        goharbor/harbor-db:v1.8.1                           "/entrypoint.sh post..."   39 seconds ago      Up 38 seconds (healthy)   5432/tcp                    harbor-db
a5fe52e1f184        goharbor/harbor-registryctl:v1.8.1                  "/harbor/start.sh"       39 seconds ago      Up 38 seconds (healthy)                               registryctl
4a74b5f3499a        goharbor/redis-photon:v1.8.1                        "docker-entrypoint.s..."   39 seconds ago      Up 38 seconds             6379/tcp                    redis
677fd84d0a70        goharbor/harbor-log:v1.8.1                          "/bin/sh -c /usr/loc..."   40 seconds ago      Up 39 seconds (healthy)   127.0.0.1:1514->10514/tcp   harbor-log

Reference:

Topics: Docker Container docker compose harbor