Prune the dangling images daily.
This commit is contained in:
parent
593d02c6e2
commit
2eae7c68db
|
@ -12,6 +12,8 @@ docker_swarm_worker_hostname: '{{ ansible_fqdn }}'
|
||||||
docker_swarm_allowed_hosts:
|
docker_swarm_allowed_hosts:
|
||||||
- '0.0.0.0/0'
|
- '0.0.0.0/0'
|
||||||
|
|
||||||
|
docker_prune_dangling_images: true
|
||||||
|
|
||||||
# Set this to one of the manager hostnames to be able to initialize the cluster
|
# Set this to one of the manager hostnames to be able to initialize the cluster
|
||||||
docker_swarm_manager_main_node_hostname: localhost
|
docker_swarm_manager_main_node_hostname: localhost
|
||||||
docker_swarm_manager_main_node_address: 127.0.0.1
|
docker_swarm_manager_main_node_address: 127.0.0.1
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
docker image prune --force > /var/log/docker-prune.log 2>&1
|
||||||
|
exit 0
|
|
@ -40,6 +40,39 @@
|
||||||
when: docker_install
|
when: docker_install
|
||||||
tags: [docker]
|
tags: [docker]
|
||||||
|
|
||||||
|
- name: Cron job that prunes the dangling images
|
||||||
|
block:
|
||||||
|
- name: Install a script that prunes the docker dangling images
|
||||||
|
copy:
|
||||||
|
src: docker-prune-dangling-images.sh
|
||||||
|
dest: /usr/local/sbin/docker-prune-dangling-images
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0744
|
||||||
|
|
||||||
|
- name: Install a cron job that prunes the docker images
|
||||||
|
cron:
|
||||||
|
name: Prune docker images
|
||||||
|
cron_file: docker-prune-images
|
||||||
|
special_time: daily
|
||||||
|
user: root
|
||||||
|
state: present
|
||||||
|
job: "/usr/local/sbin/docker-prune-dangling-images"
|
||||||
|
when: docker_prune_dangling_images
|
||||||
|
|
||||||
|
- name: Disable the cron job that prunes the docker images
|
||||||
|
cron:
|
||||||
|
name: Prune docker images
|
||||||
|
cron_file: docker-prune-images
|
||||||
|
special_time: daily
|
||||||
|
user: root
|
||||||
|
state: absent
|
||||||
|
job: "/usr/local/sbin/docker-prune-dangling-images"
|
||||||
|
when: not docker_prune_dangling_images
|
||||||
|
|
||||||
|
when: docker_install
|
||||||
|
tags: [docker, docker_prune_images]
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Remove the docker user
|
- name: Remove the docker user
|
||||||
user: name=docker state=absent
|
user: name=docker state=absent
|
||||||
|
|
Loading…
Reference in New Issue