0

So I am new to docker and wanted to start up a logspout docker container on server start up so I thought i would just chuck in a systemd start up file:

[Unit]
Description=Logspout GELF Container
After=docker.service
Requires=docker.service

[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker stop logspout-gelf
ExecStartPre=-/usr/bin/docker rm logspout-gelf
ExecStart=/usr/bin/docker run --name=logspout-gelf \
  -h $(hostname -f) \
  -v /var/run/docker.sock:/var/run/docker.sock \
  123456789.dkr.ecr.${region}.amazonaws.com/logspout-gelf:latest \
  gelf://${DOCKER_HOST}:12202

[Install]
WantedBy=multi-user.target

The service file also has a config file that is modified by a user data script on boot:

# Ansible
[Service]
Environment=DOCKER_HOST=10.100.10.1

I get an error on the restart after the DOCKER_HOST ip is populated by user data:

systemd[1]: Starting Logspout GELF Container...
Cannot connect to the Docker daemon at tcp://10.100.10.1:2375. Is the docker daemon running?
Cannot connect to the Docker daemon at tcp://10.100.10.1:2375. Is the docker daemon running?

This rolls over half a dozen times then fails. If I then set DOCKER_HOST, rm the docker container, copy the command and run it on the cli it starts without any issues.

Any ideas as to why it fails?

UPDATE

Why when the container starts with systemd does logspout default to tcp? Setting gelf+udp://${DOCKER_HOST}:12202 throws the same error above that mentions tcp. Is UDP being ignored when using systemd?

2 Answers2

0

It looks like the docker service hasn't started, running the container from the CLI will start the service and run your container.

Before running your container manually, check the status of docker.service using systemctl status docker.service. If it isn't running you'll need to add a systemd service for docker.service as well.

Briansbum
  • 121
  • 1
  • 5
  • It does look like that but the service file does have an after and requires dependant on docker.service. Also the logspout-gelf service never runs. I have started the container manually then gone back and tried the service and get the same failure. Just to throw it into the mix the container does start before user data adds the DOCKER_HOST ip to the service conf file. – SnazzyBootMan Feb 07 '18 at 10:27
0

This seems to be some oddity in logspout where it is trying to start using TCP even when gelf+udp is set. Starting outside of systemd with docker run and docker-compose both work as expected.

I don't have time to figure out why at this time so I will just let docker run --restart=unless-stopped manage the container and have the user data script on the EC2 server run the container at boot.