Reputation: 1560
I am working on ansible script for start docker damon , docker container, docker exec After start docker container with in the docker container i need to start some services.
I have installed docker engine , configured and working with some docker container in remote machines. i have used to start docker daemon with specific path, because i need to store my volumes and containers with in path.
$docker daemon -g /test/docker
My issue is when start the docker daemon its started, but not go to next process. via ansible. still running docker daemon.
---
- hosts: webservers
remote_user: root
# Apache Subversion dnf -y install python-pip
tasks:
- name: Start Docker Deamon
shell: docker -d -g /test/docker
become: yes
become_user: root
- name: Start testing docker machine
command: docker start testing
async: True
poll: 0
I follow async to start the process ,but its not working for me ,
Suggest me After start docker daemon, How to run next process.
Upvotes: 7
Views: 13014
Reputation: 7972
You can also start Docker and other services automatically when booting the machine. For that you can use the systemd
module in Ansible like this:
- name: Enable docker.service
systemd:
name: docker.service
daemon_reload: true
enabled: true
- name: Enable containerd.service
systemd:
name: containerd.service
daemon_reload: true
enabled: true
Reference: here
Upvotes: 3
Reputation: 519
In order to start the docker daemon you should use the ansible service module:
- name: Ensure docker deamon is running
service:
name: docker
state: started
become: true
any docker daemon customisation should be placed in /etc/docker/daemon.json as described in official documentation. in your case the file would look like:
{
"graph": "/test/docker"
}
In order to interact with containers, use the ansible docker_container module:
- name: Ensure My docker container is running
docker_container:
name: testing
image: busybox
state: started
become: true
Try to avoid doing anything in ansible using the shell module, since it can cause headaches down the line.
Upvotes: 9