Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker daemon start using ansible

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.

like image 583
Rajkumar .E Avatar asked Feb 04 '17 13:02

Rajkumar .E


People also ask

How do you start Docker daemon?

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.

How do I run a Docker container in Ansible?

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.

Does Docker use Ansible?

As mentioned, you can use Ansible to automate Docker and to build and deploy Docker containers.


1 Answers

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.

like image 159
gbolo Avatar answered Oct 30 '22 20:10

gbolo