I'm trying to deploy a Docker service into swarm but always ending up with running container on my localhost (the one I use as a docker swarm manager) and no service
Here's my setup:
I have 3 node Docker (v. 1.12.1) swarm that includes one host running as manager and two worker nodes all running on CentOS 7. On the manager node (localhost) I run Ansible (v. 2.1.1.0) playbook and the swarm is already configured and is running
Swarm: active
NodeID: d9h5xa832ax7wzeq8q44fjld3
Is Manager: true
ClusterID: 9cztoin3gy2ntbwehsmrkjuxi
Managers: 1
Nodes: 3
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot Interval: 10000
Heartbeat Tick: 1
Election Tick: 3
Dispatcher:
Heartbeat Period: 5 seconds
CA Configuration:
Expiry Duration: 3 months
Node Address: 10.25.190.209
Starting with a playbook that has this code
- hosts: localhost
name: Run JMeter test
vars_files:
- user.config.yml
vars:
execute_tpcds_test : "{{ run_tpcds_test }}"
roles:
- { role: run_jmeter, when: execute_tpcds_test is defined and execute_tpcds_test ==1 }
Which calls this role:
- name: Deploy tpcds_tpg service to swarm
docker_service:
project_name: tpcds-tpg
definition:
version: '2'
services:
run_tests:
image: 'pbench/tpcds_tpg'
volumes:
- /opt/pbench/run_output/
command: ./run_jmeter.sh "{{jmeter_output_dir}}"
register: output
- debug: var=output
When I run ansible-playbook ./site.yml
I end up with a running container. Doing docker ps -a
displays
[pdo@sdl02133 tpcds-tpg]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fef245b41365 pbench/tpcds_tpg "./run_jmeter.sh /opt" 21 seconds ago Up 20 seconds tpcdstpg_run_tests_1
And doing docker service ls
shows no services running so it looks like docker_service
deploys my image as a local container and not as a service on the swarm
So my assumption was that if I have an active swarm on the machine that is a swarm manager and I use Ansible docker_service
module, then it will automatically be aware of the swarm and deploy the service to it. Looks like my assumption is wrong and I cannot find any docs, blog posts, etc. that would hint me what to do and what I am missing. Ansible experts please help!
Managing Docker Containers Using Ansible Modules Ansible has several modules for managing Docker; a few of these are docker_image, docker_container, and docker_service.
Important note: At the time of this writing, Docker Swarm is not dead. It is included in the Docker Community edition and Docker has not announced plans to deprecate it.
Docker Swarm is not being deprecated, and is still a viable method for Docker multi-host orchestration, but Docker Swarm Mode (which uses the Swarmkit libraries under the hood) is the recommended way to begin a new Docker project where orchestration over multiple hosts is required.
Swarm mode has two types of services: replicated and global. For replicated services, you specify the number of replica tasks for the swarm manager to schedule onto available nodes.
The Ansible module uses Docker Compose which doesn't work with Swarm Mode at the moment. If you run docker-compose
on a node in a Swarm, it just issues docker run
commands - which is why you have containers running on a single host instead of services running in the Swarm.
You can track swarm mode support in Compose with issue 3656, but when that does happen there may well need to be a change to the Ansible module too (unless Compose is changed to have swarm mode detection logic).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With