Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用systemd运行docker容器_Docker_Systemd - Fatal编程技术网

使用systemd运行docker容器

使用systemd运行docker容器,docker,systemd,Docker,Systemd,我有一个在CentOS 7上使用systemd启动docker容器的服务定义: [Unit] Description=MappingService After=portal.service Requires=docker.service [Service] TimeoutStartSec=3000 Type=forking WorkingDirectory=/home/user/Downloads/MS_0.3.4_artifact ExecStartPre=-/bin/docker rm -

我有一个在CentOS 7上使用systemd启动docker容器的服务定义:

[Unit]
Description=MappingService
After=portal.service
Requires=docker.service

[Service]
TimeoutStartSec=3000
Type=forking
WorkingDirectory=/home/user/Downloads/MS_0.3.4_artifact
ExecStartPre=-/bin/docker rm -f eb-mapping-service-container
ExecStartPre=/home/user/Downloads/MS_0.3.4_artifact/deploy.sh /home/user/Downloads/MS_0.3.4_artifact/eb-mapping-service.tgz
ExecStartPre=/bin/docker run -v /dev/log:/dev/log -d -ti --log-driver=journald --network=bridge -p 9090:9090 --name eb-mapping-service-container eb-mapping-service  /bin/bash -c "cd /build/MappingService; ./start_multiple_clients_mapping_service.sh"
ExecStart=/bin/docker start -a eb-mapping-service-container
ExecStop=/bin/docker stop eb-mapping-service-container

[Install]
WantedBy=multi-user.target
这项服务有效。它启动的Docker容器已启动。 每当我启动计算机时,它都在运行。我对这项服务的问题是,它从未达到活动(运行)状态。相反,它卡在“激活(启动)”状态。 “start\u multiple\u clients\u mapping\u service.sh”脚本启动node.js服务器并开始侦听,因此它不会直接退出

我到处都找遍了,翻遍了Docker的文档,找不到答案

此外,如果我从docker start命令中删除“-a”,那么即使容器将启动并运行,状态也将为Inactive(dead)。 更新: 过了一段时间,我没有一个确切的数字,服务失败的原因是超时。这不是3000秒之后,而是更早尽管服务失败,docker仍在广播中,可以使用
我已经用
docker容器ls

问题:

如何更改服务定义以反映docker的活动(运行)状态?

我理解这个问题。有两件事不对:

  • docker run命令不应与标志-d和-ti一起使用
  • 类型应设置为exec,而不是forking

  • 完成这两项更改后,我获得了备受追捧的活动(运行)状态,Docker已成功启动。

    问题在于,您的服务实际上并没有像您在
    Type=
    中指定的那样分叉。容器进程不是
    docker start
    进程的子进程,它是docker守护进程的子进程,docker守护进程单独运行(更正式地说,它有一个较长的层次结构,但主要的一点是它与
    docker start
    进程无关)。因为您将您的服务分类为
    forking
    systemd
    等待
    docker start
    生成子进程并退出,让子进程继续运行,但是
    docker start
    继续运行(因为
    -a
    选项),所以
    systemd
    认为服务正在启动。