The Harbor Docker registry doesn’t automatically start when your server reboots. Find out how to make this happen.
After installing and using the Docker Harbor registry server, I couldn’t be more pleased with how well it functions (and the purpose it serves). And if you and your data center depend on having an on-premises Docker registry that is capable of scanning images for vulnerabilities, you’re going to want this server up and running 24/7.
That 24/7 is the kicker. Why? Because out of the box, Docker Harbor has no built-in mechanism for restarting should the server be rebooted or the service stop. This is a problem, especially when you have no idea how to restart the service. You’ll be unable to gain access to your Harbor registry nor have the ability to scan images for vulnerabilities.
That is not acceptable.
Fortunately, there is a way to start the service manually (as well as add it to systemd). Let’s find out how.
SEE: 10 things companies are keeping in their own data centers (TechRepublic download)
How to start Harbor manually
Starting the service manually is quite simple. Here’s how:
- Open a terminal window (or log into your server hosting Harbor).
- Change into the Harbor installation directory.
- Issue the command sudo docker-compose start.
You should see the Harbor services starting, one by one, until everything is back up and running (Figure A).
Of course, you don’t want to have to do this every single time you reboot your server. With that in mind, how do you solve such an issue? You turn to systemd.
How to create a systemd service file in Harbor
We’ll create a systemd service file, specifically for Harbor. To do this, issue the command:
sudo nano /etc/systemd/system/harbor.service
In that file, paste the following:
[Unit] Description=Harbor Service After=network.target docker.service [Service] Type=simple WorkingDirectory=/PATH/TO/harbor ExecStart=/usr/local/bin/docker-compose -f /PATH/TO/harbor/docker-compose.yml$ ExecStop=/usr/local/bin/docker-compose -f /PATH/TO/harbor/docker-compose.yml $ RemainAfterExit=yes [Install] WantedBy=multi-user.target
Where /PATH/TO is the actual path to your harbor installation directory. Save and close that file.
With the file in place, stop and start the service with the commands:
sudo systemctl stop harbor sudo systemctl start harbor
Because the service takes a bit of time to both stop and start, make sure to be patient and not Ctrl + c back to your prompt. Wait until systemctl hands you the prompt back. You can then issue the command:
sudo systemctl status harbor
You should see the Harbor services are now running (Figure B).
Finally, you’ll want to enable the Harbor service with the command:
sudo systemctl enable harbor
And now, if/when your server reboots, the Harbor service will automatically start—no need to do so manually. Rest assured you will always be able to reach that registry.