在ubuntu 15.04上使用systemd启动docker-compose

前端之家收集整理的这篇文章主要介绍了在ubuntu 15.04上使用systemd启动docker-compose前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个docker-compose项目,我想通过systemd控制.在upstart中,我会使用如下所示的脚本:
description "Start/Stop server"
author "Jim Cortez"

start on filesystem and started docker
stop on runlevel [!2345]

respawn limit 3 240

pre-start script
    # wait (if necessary) for our docker context to be accessible
    while [ ! -f /projects/my_server/docker-compose.yml ]
    do
      sleep 1
    done
    /usr/local/bin/docker-compose -f /projects/my_server/docker-compose.yml up -d
end script

script
    sleepWhileAppIsUp(){
        while docker ps | grep "$1" >/dev/null; do
            sleep 2
        done
    }

    sleepWhileAppIsUp "my_server"
end script

# stop docker container after the stop event has completed
post-stop script
    if docker ps | grep my_server;
    then
        /usr/local/bin/docker-compose -f /projects/my_server/docker-compose.yml stop
    fi
end script

(以上改编自here)

但是,我现在在运行Ubuntu 15.04的docker主机上运行,​​该主机已切换到systemd.如何将上述内容作为systemd服务脚本?只需启动docker-compose守护程序,就不允许systemd在发生故障时进行跟踪和重启.

这是我到目前为止:

[Unit]
Description=My Server container
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/usr/local/bin/docker-compose -f /projects/my_server/docker-compose.yml up -d
ExecStop=/usr/local/bin/docker-compose -f /projects/my_server/docker-compose.yml stop

[Install]
WantedBy=local.target
我建议删除-d选项.在这种情况下,您不需要在后台运行容器.

猜你在找的Ubuntu相关文章