Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible `docker_container` options `network_mode` and `networks` - are they intersecting?

I'm building a playbook where I want to deploy a container to a host network. The Ansible docs mention two options: network_mode and networks. If I want to connect my container to the default host network, is the option (syntax as in Ansible playbooks):

network_mode: host

equivalent to:

networks:
  name: host

?

If not, what would be the network to which the container connects in both cases (if it connects at all?)

like image 312
Wladek Surala Avatar asked Jul 04 '18 13:07

Wladek Surala


People also ask

How do you use the Docker_container Ansible module?

The URL or Unix socket path used to connect to the Docker API. To connect to a remote host, provide the TCP connection string. For example, 'tcp://192.0.2.23:2376'. If TLS is used to encrypt the connection, the module will automatically replace 'tcp' in the connection URL with 'https'.

What Ansible module can you use to manage Docker containers?

docker_container – manage docker containers — Ansible Documentation. For community users, you are reading an unmaintained version of the Ansible documentation. Unmaintained Ansible versions can contain unfixed security vulnerabilities (CVE). Please upgrade to a maintained version.


1 Answers

This is more of a Docker question than an Ansible question. You can find additional details beyond what I've put here in my answer by reading through, for example, the Network settings section of the docker run documentation.

The networks key allows you to connect your container to a named network.

The network_mode key allows you to select the type of network to create for your container (host, bridge, none, or the network environment of a specific container). It doesn't allow you to connect directly to a named network.

So if you have a network named host available that uses host networking mode, then:

network_mode: host

Is equivalent to:

networks:
  - name: host

But in general, they let you do distinct things.

like image 124
larsks Avatar answered Sep 28 '22 07:09

larsks