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?