docker_container模塊redis
一、docker_container模塊主要是用於ansible-playbook操做docker容器的一個模塊,使用該模塊能夠實現批量建立docker容器docker
Ansible 中部署 docker 鏡像主要須要的是 docker_container, docker_image, docker_service 三個模塊。其中 docker_container 用於部署 docker 容器,docker_image 用於編譯鏡像,docker_service 模塊用於部署 docker compose。ide
通常ansible-playbook的劇本是這樣定義的,例如first.yaml所示:spa
---- hosts: all remote_user: redis vars: container_name: "redis" container_image: "redis:4.0.1" working_dir: "/data/redis_test" tasks: - name: remove container docker_container: name: "{{ container_name }}" state: absent - name: create working_dir directory file: path: "{{ item }}" state: directory with_items: - "{{ working_dir }}" # docker run -p 6379:6379 --name redis -d redis:4.0.1 - name: create container docker_container: name: "{{ container_name }}" image: "{{ container_image }}" ports: - "6379:6379"
接着就可使用ansible-playbook來進行部署了,例如:ansible-playbook -i hosts first.ymlorm