85355

Docker and systemd - service stopping after 10 seconds

I'm having trouble getting a Docker container to stay up when it's started by systemd. When I start it manually with sudo docker start containername, it stays up without trouble, but when it's started via systemd with sudo systemctl start containername, it stays up for 10 seconds then mysteriously dies, leaving messages in syslog something like the following:

Mar 13 14:01:09 hostname docker[329]: time="2015-03-13T14:01:09Z" level="info" msg="POST /v1.17/containers/containername/stop?t=10" Mar 13 14:01:09 hostname docker[329]: time="2015-03-13T14:01:09Z" level="info" msg="+job stop(containername)"

I am making the assumption that it's systemd killing the process, but I can't work out why it might be happening. The systemd unit file (/etc/systemd/system/containername.service) is pretty simple, as follows:

[Unit] Description=MyContainer After=docker.service Requires=docker.service [Service] ExecStart=/usr/bin/docker start containername ExecStop=/usr/bin/docker stop containername [Install] WantedBy=multi-user.target

Docker starts fine on boot, and it looks like it does even start the docker container, but no matter if on boot or manually, it then quits after exactly 10 seconds. Help gratefully received!

Answer1:

Solution: The start command seems to need the -a (attach) parameter as described in the documentation when used in a systemd script. I assume this is because it by default forks to the background, although the systemd expect daemon feature doesn't appear to fix the issue.

from the docker-start manpage:

-a, --attach=true|false Attach container's STDOUT and STDERR and forward all signals to the process. The default is false.

The whole systemd script then becomes:

[Unit] Description=MyContainer After=docker.service Requires=docker.service [Service] ExecStart=/usr/bin/docker start -a containername ExecStop=/usr/bin/docker stop containername [Install] WantedBy=multi-user.target

Recommend

  • How to read a XML file with spark that contains multiple namespaces?
  • Apache crashes with error R6016 not enough space for thread data
  • Joda DateTime Invalid format
  • R update values based on event
  • Kubernetes 1.7 on Google Cloud: FailedSync Error syncing pod, SandboxChanged Pod sandbox changed, it
  • Docker container for google cloudML on compute engine - authenticating for mounting bucket
  • Repainting JPanel after button click
  • Uber API - requests endpoint cannot read read json
  • How do I check if System::Collections:ArrayList is empty / nullptr / null?
  • Unable to play media with vlc ocx
  • Embedded Google Maps in Rails not responsive
  • New Firebase failed: First argument must be a valid firebase URL and the path can't contain “.”
  • JSON encode and decode on PHP
  • Building Qt project for C++11 standard
  • converter json to two dimensional array
  • How do I get the list of bad records that didn't load in Bigquery?
  • How to handle elastic beanstalk deployment so it uploads only changed files
  • How can I tell a form not to dispose a particular control when it closes?
  • uml Composition relationships to RDF and OWL
  • Azure table store snapshot/backup capability
  • SonarQube: Cannot deactivate rule with missing quality profile
  • Eclipse CDT error: Unable to compile
  • xtable package: Skipping some rows in the output
  • Could not find rake using whenever rails
  • Q promise. Difference between .when and .then
  • How to rebase a series of branches?
  • Change JButton Shape while respecting Look And Feel
  • jQuery show() function is not executed in Safari if submit handler returns true
  • Can Jackson SerializationFeature be overridden per field or class?
  • Trying to switch camera back to front but getting exception
  • Redux, normalised entities and lodash merge
  • what is the difference between the asp.net mvc application and asp.net web application
  • 0x202A in filename: Why?
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Android Studio and gradle
  • Free memory of cv::Mat loaded using FileStorage API
  • Memory offsets in inline assembly
  • Turn off referential integrity in Derby? is it possible?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize