수행원시스템 가이드이 샘플 구성에 문제가 있습니다.
[Unit]
Description=MyApp
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill busybox1
ExecStartPre=-/usr/bin/docker rm busybox1
ExecStartPre=/usr/bin/docker pull busybox
ExecStart=/usr/bin/docker run --name busybox1 busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done"
[Install]
WantedBy=multi-user.target
시스템이 실행되는 동안 "systemctl start hello"를 실행하면 docker가 시작되지만 부팅 시 systemd를 통해 시작하도록 "hello.service"를 활성화하고 컴퓨터를 다시 시작하면 다음 오류가 발생합니다.
-- Reboot --
Mar 15 01:17:44 general systemd[1]: Starting MyApp...
Mar 15 01:17:47 general docker[510]: Error response from daemon: No such container: busybox1
Mar 15 01:17:47 general docker[510]: time="2015-03-15T01:17:47Z" level="fatal" msg="Error: failed to kill one or more containers"
Mar 15 01:17:47 general docker[637]: Error response from daemon: No such container: busybox1
Mar 15 01:17:47 general docker[637]: time="2015-03-15T01:17:47Z" level="fatal" msg="Error: failed to remove one or more containers"
Mar 15 01:17:47 general systemd[1]: hello.service: control process exited, code=exited status=1
Mar 15 01:17:47 general systemd[1]: Failed to start MyApp.
Mar 15 01:17:47 general systemd[1]: Unit hello.service entered failed state.
Mar 15 01:17:47 general systemd[1]: hello.service failed.
Mar 15 01:17:47 general docker[673]: Pulling repository busybox
Mar 15 01:17:47 general docker[673]: time="2015-03-15T01:17:47Z" level="fatal" msg="Get https://index.docker.io/v1/repositories/library/busybox/images: dial tcp: lookup index.docker.io: connection refused"
내가 뭘 잘못하고 있는지 아시나요?
답변1
시작할 때 실행하려면 이 network-online.target
서비스를 사용해야 합니다. 이 명령을 실행하기 전에 네트워크가 작동 중인지 확인해야 합니다 docker pull
. 바라보다"네트워크 연결 후 서비스 실행"자세한 내용은 systemd 문서에서 확인하세요.
다음은 나에게 효과적이었습니다.
[Unit]
Description=MyApp
Requires=docker.service network-online.target
After=docker.service network-online.target
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill busybox1
ExecStartPre=-/usr/bin/docker rm busybox1
ExecStartPre=/usr/bin/docker pull busybox
ExecStart=/usr/bin/docker run --name busybox1 busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done"
[Install]
WantedBy=multi-user.target
답변2
나는 제안된 것을 시도했습니다:
Requires=docker.service network-online.target
After=docker.service network-online.target
그러나 그것은 작동하지 않았습니다. 나는 가지고있다:
-- Reboot --
Feb 09 23:20:24 coreos-512mb-fra1-01 systemd[1]: Starting New Relic Linux Server Monitor (nrsysmond)...
Feb 09 23:20:24 coreos-512mb-fra1-01 docker[782]: Failed to kill container (nrsysmond): Error response from daemon: Cannot kill container nrsysmond: Container c608c10f44c06c550492e872773b0d5a59a7b86e639f63487f6186983a4f786b is not running
Feb 09 23:20:25 coreos-512mb-fra1-01 docker[787]: nrsysmond
Feb 09 23:20:25 coreos-512mb-fra1-01 docker[794]: Pulling repository docker.io/newrelic/nrsysmond
Feb 09 23:20:25 coreos-512mb-fra1-01 docker[794]: Error while pulling image: Get https://index.docker.io/v1/repositories/newrelic/nrsysmond/images: dial tcp: lookup index.docker.io: Temporary failure in name resolution
Feb 09 23:20:25 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Control process exited, code=exited status=1
Feb 09 23:20:25 coreos-512mb-fra1-01 systemd[1]: Failed to start New Relic Linux Server Monitor (nrsysmond).
Feb 09 23:20:25 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Unit entered failed state.
Feb 09 23:20:25 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Failed with result 'exit-code'.
문제 추가 Restart
및 RestartSec
수정:
# Restart after crash
Restart=always
# Give the service 10 seconds to recover after the previous restart
RestartSec=10s
우아하지는 않지만 작동합니다. 로그는 다음과 같습니다.
Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: Starting New Relic Linux Server Monitor (nrsysmond)...
Feb 09 23:23:57 coreos-512mb-fra1-01 docker[792]: Failed to kill container (nrsysmond): Error response from daemon: Cannot kill container nrsysmond: Container 31fb78809
Feb 09 23:23:57 coreos-512mb-fra1-01 docker[797]: nrsysmond
Feb 09 23:23:57 coreos-512mb-fra1-01 docker[804]: Pulling repository docker.io/newrelic/nrsysmond
Feb 09 23:23:57 coreos-512mb-fra1-01 docker[804]: Error while pulling image: Get https://index.docker.io/v1/repositories/newrelic/nrsysmond/images: dial tcp: lookup ind
Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Control process exited, code=exited status=1
Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: Failed to start New Relic Linux Server Monitor (nrsysmond).
Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Unit entered failed state.
Feb 09 23:23:57 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Failed with result 'exit-code'.
Feb 09 23:24:08 coreos-512mb-fra1-01 systemd[1]: newrelic.service: Service hold-off time over, scheduling restart.
Feb 09 23:24:08 coreos-512mb-fra1-01 systemd[1]: Stopped New Relic Linux Server Monitor (nrsysmond).
Feb 09 23:24:08 coreos-512mb-fra1-01 systemd[1]: Starting New Relic Linux Server Monitor (nrsysmond)...
Feb 09 23:24:08 coreos-512mb-fra1-01 docker[869]: Failed to kill container (nrsysmond): Error response from daemon: Cannot kill container nrsysmond: No such container:
Feb 09 23:24:08 coreos-512mb-fra1-01 docker[875]: Failed to remove container (nrsysmond): Error response from daemon: No such container: nrsysmond
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: latest: Pulling from newrelic/nrsysmond
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: 6ffe5d2d6a97: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: f4e00f994fd4: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: e99f3d1fc87b: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: a3ed95caeb02: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: a3ed95caeb02: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: 65cdb07f703d: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: a3ed95caeb02: Already exists
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: Digest: sha256:c184f97452321baa0b0ee4ee402e3aaa204f041beb7a71a347db6c4efecba07f
Feb 09 23:24:10 coreos-512mb-fra1-01 docker[883]: Status: Image is up to date for newrelic/nrsysmond:latest
Feb 09 23:24:10 coreos-512mb-fra1-01 systemd[1]: Started New Relic Linux Server Monitor (nrsysmond).
DigitalOcean CoreOS에서 이 문제가 발생했기 때문에 해당 리소스에서 도움을 찾았습니다. 하나 있다철사이 질문과 관련이 있습니다. 이는 다음과 같이 제안합니다.
After=early-docker.service systemd-networkd-wait-online.service
Requires=early-docker.service systemd-networkd-wait-online.service
Before=early-docker.target
그러나 이러한 줄로 인해 Docker가 중단/정지됩니다. 내 서비스와 관련된 모든 프로세스를 종료하고 Docker 서비스를 다시 시작하여 다시 응답해야 했습니다.
도커 버전:
docker -v
Docker version 1.10.0, build e21da33