How to restart the Docker Harbor services

The Harbor Docker registry doesn't automatically start when your server reboots. Find out how to make this happen.

How to restart the Docker Harbor services

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.

Additional resources:

How to start Harbor manually

Starting the service manually is quite simple. Here's how:

  1. Open a terminal window (or log into your server hosting Harbor).
  2. Change into the Harbor installation directory.
  3. 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).

Figure A


Restarting the Harbor services.

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.

SEE: 10 things companies are keeping in their own data centers (TechRepublic download)

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:

Description=Harbor Service docker.service
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 $

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).

Figure B


Our systemd file is working like a charm.

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.

Also see

  • Hyperconverged infrastructure: A cheat sheet (TechRepublic)
  • Hiring kit: Database administrator (TechRepublic Premium)
  • How to create and manage Docker networks (TechRepublic)
  • How to export and import containers with Docker (TechRepublic)
  • How to install and use Docker on Windows (TechRepublic)
  • How to run cleanup tasks with Docker using these 4 tips (TechRepublic)
  • How to spin up a quick Docker test platform with boot2docker (TechRepublic)
  • What is Docker and why is it so darn popular? (ZDNet)
  • How hyperscale data centers are reshaping all of IT (ZDNet)
  • Best cloud services for small businesses (CNET)
  • DevOps: More must-read coverage (TechRepublic on Flipboard)
  • dockerhero.jpg

    Image: Docker

    By Jack Wallen

    Jack Wallen is an award-winning writer for TechRepublic, The New Stack, and Linux New Media. He's covered a variety of topics for over twenty years and is an avid promoter of open source. For more news about Jack Wallen, visit his website jackwallen....