garethr-docker
garethr-docker copied to clipboard
puppet wants to create containers after the host is rebooted. with restarts => always. while the container with that name already exists.
When i run puppet, it runs all the containers specified in puppet with hiera. the puppet agent run is successful. But when i restart the server, docker runs the containers on boot as i have mentions restart: always
in my hiera config.After the boot when puppet agent is run, it throws error because it tries to create those containers again and docker::run fails because the containers with the exact name is already present.
This is my hiera config.
someclass::docker::containers:
reverse_proxy:
image: jwilder/nginx-proxy
ports:
- '80:80'
volumes:
- '/etc/nginx/sites-enabled/:/etc/nginx/custom-conf/'
- '/etc/nginx/custom-conf/custom.conf:/etc/nginx/conf.d/custom.conf'
- '/var/run/docker.sock:/tmp/docker.sock:ro'
detach: true
restart: always
use_name: true
health_check:
image: nginx
ports: 81:80
detach: true
restart: always
use_name: true
and from puppet i use it as:
create_resources(docker::run, $containers)
Error on puppet agent:
Error: /Stage[main]/SomeClass::Docker/Docker::Run[health_check]/Exec[run health_check with docker]/returns: change from notrun to 0 failed: docker run -d --net bridge -m 0b --detach=true -p 81:80 --name health-check --cidfile=/var/run/docker-health-check.cid --restart="always" nginx returned 125 instead of one of [0]
I also added use_name: true
but thats been deprecated. so doesn't seem to a problem regarding that.
Version:
garethr-docker 5.0.0
garethr-docker 5.3.0
on AmazonLinux
@itsSaad when Docker returns the error code 125 it is an issue with the demon. Please see here https://docs.docker.com/engine/reference/run/#exit-status. Is the Docker Deamon starting correctly after the reboot?
The reason is probably that the cid file is in /var/run, which is cleaned on reboot. Maybe put this in /var/cache/puppet-garethr-docker
or /var/lib/puppet/garethr-docker
or similar?