danday74
danday74

Reputation: 56946

Can Ansible deploy Docker containers remotely?

I understand that Ansible is used to automate the provisioning / configuration of remote servers, typically over SSH.

However, this document states ..

http://docs.ansible.com/ansible/intro_inventory.html#non-ssh-connection-types

docker - This connector deploys the playbook directly into Docker containers using the local Docker client.

My question is ... can Ansible create and provision a Docker container on a remote machine or only on the machine on which Ansible is running (namely the controller machine)?

Any tips or any good links greatly appreciated.

Upvotes: 2

Views: 8922

Answers (3)

I am working with it. If you want to check the project: https://github.com/ppc64le/ciaas

I use the docker_service module and it runs fine.

Update: new link for Ansible documentation on docker_service module https://docs.ansible.com/ansible/2.5/modules/docker_service_module.html

Upvotes: 2

techraf
techraf

Reputation: 68459

Of course it can deploy containers on remote machines. There are several modules for Docker, but you are asking for docker_container:

---
- hosts: docker_host
  tasks:
    - name: Ensure web based hello world container is running
      docker_container:
        name: web_hello_world
        image: tutum/hello-world
        ports:
          - 80:80

Also have a look at docker_image if you want to build a Docker image.


Docker connection type, which you quoted in the question, is used to connect directly to the Docker container (and run tasks inside the container), not to the machine running the containers. So unless you ran Docker inside a container, this type of connection is not used for deploying Docker containers.

And even so, the quote refers to a "local Docker client", not local Docker Engine.

Upvotes: 3

Nick Burke
Nick Burke

Reputation: 969

Hopefully, I'm understanding your question correctly.

Any machine that has the docker client or API libraries (EG: docker-py), network access, and is configured correctly can manipulate the docker daemon remotely.

To do this, you must configure the docker daemon to listen remotely. WARNING: by default it is insecure with no authentication! Make sure to set up SSL with cert authentication.

After that, you can install the docker client (or libraries) and the relevant certificates. You'll need to set environment variables on Vagrant if you are using the client. Those variables are:

DOCKER_HOST=docker_host:docker_port
DOCKER_TLS_VERIFY=true

You should put the certificates in ~/.docker with the following name conventions: ca.pem cert.pem key.pem

At that point, your vagrant virtual can manipulate a remote docker host.

Upvotes: 2

Related Questions