Ansible - recreate ghost container
Page content
YAML file
state:absent
는 현재 존재하는 container를 중지시키고, 삭제한다.
단순히 stop만 시키려면 state:stopped
로 지정하면 된다.
pull: yes
옵션을 사용하면 항상 최신 image를 pull한다고 한다.
recreate Use with present and started states to force the re-creation of an existing container.
mbpr15:ansible cychong$ cat recreate_container_ghost.yaml
---
- hosts: mini2
tasks:
- name: Stop and remove contianer
docker_container:
name: ghost
state: absent
- name: Create ghost Container
docker_container:
name: ghost
image: ghost
# always pull the latest image
pull: yes
state: started
recreate: yes
volumes:
- "/Users/cychong/Dropbox/Apps/ghost/content/:/var/lib/ghost/content"
- "/Users/cychong/Dropbox/Apps/ghost/config.production.json:/var/lib/ghost/config.production.json"
ports:
- "2368:2368"
env:
NODE_ENV: production
mbpr15:ansible cychong$ ansible-playbook recreate_container_ghost.yaml
PLAY [mini2] ***************************************************************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************************************************
ok: [mini2]
TASK [Stop and remove contianer] *******************************************************************************************************************************************
changed: [mini2]
TASK [Create ghost Container] **********************************************************************************************************************************************
changed: [mini2]
PLAY RECAP *****************************************************************************************************************************************************************
mini2 : ok=3 changed=2 unreachable=0 failed=0