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.
On MacOS go to the whale in the taskbar > Preferences > Daemon > Advanced. You can also start the Docker daemon manually and configure it using flags. This can be useful for troubleshooting problems. Many specific configuration options are discussed throughout the Docker documentation.
To handle docker containers from ansible, the requirement is to install docker SDK, to install that we will install pip, and using pip we will download docker SDK. Lastly, start a docker service. We want to create a container in such a way that, we can connect the docker container using ssh public key authentication.
As mentioned, you can use Ansible to automate Docker and to build and deploy Docker containers.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With