docker_container alters the ports when used to restart a docker contaienr
STEPS TO REPRODUCE
I wanted the equivalent of the below using docker_container
- name: restart containers
shell: "docker stop {{ item }}; docker start {{ item }}"
with_items: "{{ docker_names.stdout_lines }} "
this is my docker_container create task
- name: install lucee5 docker instance 1
docker_container:
docker_api_version: "{{ dockerapi_version }}"
etc_hosts: "{{ docker_extra_hosts }}"
name: "{{ site_prefix }}{{ docker_port }}"
image: "{{ site_docker_image }}"
state: started
restart_policy: on-failure
restart_retries: 5
pull: yes
published_ports:
- "{{ docker_port }}:8888"
this is my restart that fails
- name: restart container
docker_container:
api_version: "{{ dockerapi_version }}"
pull: no
name: "{{ item }}"
image: "{{ site_docker_image }}"
state: started
restart: yes
with_items: "{{ docker_names.stdout_lines }} "
EXPECTED RESULTS
The restarted container should of had the same published port i.e.
0.0.0.0:8815->8888/tcp
the problem is
after the creation of the container it has port of
0.0.0.0:8815->8888/tcp
but after the restart this is removed and hence 8815 on host is no longer mapped to 8888 on container
(ports output is now 8009/tcp, 8080/tcp, 8888/tcp and it should be 8009/tcp, 8080/tcp, 0.0.0.0:8815->8888/tcp)
ISSUE TYPE
COMPONENT NAME
docker_container
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Ubuntu Trusty on EC2
SUMMARY
docker_container alters the ports when used to restart a docker contaienr
STEPS TO REPRODUCE
EXPECTED RESULTS
The restarted container should of had the same published port i.e. 0.0.0.0:8815->8888/tcp
the problem is after the creation of the container it has port of 0.0.0.0:8815->8888/tcp
but after the restart this is removed and hence 8815 on host is no longer mapped to 8888 on container (ports output is now 8009/tcp, 8080/tcp, 8888/tcp and it should be 8009/tcp, 8080/tcp, 0.0.0.0:8815->8888/tcp)
using the shell variant it works as expected.
ACTUAL RESULTS
It all works