Start a Docker Container with the help of Ansible

Start a Docker Container with the help of Ansible

Introduction:

The task is to pull docker image and launch a create a docker container with the help of ansible

Requirement:

  1. A controller node with ansible installed and configured
  2. A Managed node where the docker container need to be hosted

Tasks:

  1. Update the ansible inventory with the IP Address of managed node, user name to connect, SSH key to connect.

Article content

2. Start developing the playbook. Write the task to install docker package and start the docker service.

Article content

3. Since the docker module is not included with ansible core, download it with from galaxy collection with below command:

ansible-galaxy collection install community.docker

4. Once it is installed, all the modules related to docker will be available. Use community.docker.docker_image module to pull the docker image.

Article content

5. The next task will be to start a container. This can be done with “community.docker.docker_container” module.

Article content

6. Once the playbook is ready, execute it and we will be able to see a new container has been launched.

Article content
Article content


To view or add a comment, sign in

Others also viewed

Explore topics