Docker Community Forums

Share and learn in the Docker community.

How to make a Systemd Unit for docker-compose?

I’ve tried to make a service Unit to initialize some Docker images by docker-compose in Systemd. I have saw somes examples at Internet, but the only works, there is a issue with these harbor.service file:

Description=Servico de manutencao do Harbor docker.service
ExecStart=/usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml down

I start de Unit and after I receive this status:

# systemctl start harbor
# systemctl status harbor
● harbor.service - Servico de manutencao do Harbor
Loaded: loaded (/etc/systemd/system/harbor.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2016-12-19 20:09:44 BRST; 16min ago
Main PID: 2028 (docker-compose)
Memory: 34.3M
CGroup: /system.slice/harbor.service
├─2028 /usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up
└─2029 /usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up

Everything is OK, all Dockers container running. I can stop the
harbor service without any problem. But now I have two docker-compose
Is that normal? Could I have problems in Future with these two
process? How to make service Unit file better for docker-compose?


What happens when you start the same command manually (Out of the context of systemd)?
Stop the service with systemctl stop harbor
Run /usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up
do your “ps” magic here.

(Tenha um bom dia :P)

Out of Context of systemd everything is ok.
I run a “systemct stop harbor” and command:
/usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up
All how was expected… docker-compose has started all containers and run in frontground (I think that is inherite of Harbor). So I have now two process again:

[root@hub2 ~]# /usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml ps
      Name                     Command               State                    Ports                   
harbor-db  mysqld      Up      3306/tcp                                 
harbor-jobservice   /harbor/harbor_jobservice        Up                                               
harbor-ui           /harbor/harbor_ui                Up                                               
nginx               nginx -g daemon off;             Up>443/tcp,>80/tcp 
registry            / serve /etc/ ...   Up      5000/tcp                                 
[root@hub2 ~]# 
[root@hub2 ~]# ps aux|grep docker-compose
root     21662  0.0  0.0   9712  1784 pts/0    S+   18:27   0:00 /usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up
root     21663  0.3  1.1 652708 22424 pts/0    Sl+  18:27   0:01 /usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up
root     22405  0.0  0.0 112672   976 pts/1    S+   18:34   0:00 grep --color=auto docker-compose
[root@hub2 ~]#