wunzeco / ansible-docker

Install and configure docker-engine
9 stars 9 forks source link

docker_opts/docker_engine_opts not respected on ubuntu 16.04 #1

Closed pangdudu closed 7 years ago

pangdudu commented 8 years ago

Hi there,

first of all thanks for the great role. I am experiencing some problems configuring my docker install with the role:

    - role: wunzeco.docker
      docker_engine_opts: "-D -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"

the result in /etc/default/docker is this:

DOCKER_OPTS="- D   - H   t c p : / / 0 . 0 . 0 . 0 : 2 3 7 5   - H   u n i x : / / / v a r / r u n / d o c k e r . s o c k"

another problem is that, ubuntu 16.04 uses upstart to start docker, via configuration in this file:

/lib/systemd/system/docker.service

with the line:

ExecStart=/usr/bin/docker daemon -H fd://

so any configuration via /etc/default/docker would not be respected anyways, correct?

I am hacking it right now with a role which does this:


---
- name: 'change docker upstart file'
  shell: 'sed -i "s/-H fd:\/\//-H tcp:\/\/0.0.0.0:2375 -H unix:\/\/\/var\/run\/docker.sock/g" /lib/systemd/system/docker.service'
- name: 'reload systemctl daemons'
  shell: "systemctl daemon-reload"
- service: name=docker state=restarted

thanks again, hope i could help.

hbokh commented 8 years ago

Also same sort of issues on CentOS7 and systemd / /etc/systemd/system/docker.service.d/docker.conf...

wunzeco commented 7 years ago

@pangdudu @hbokh Sorry guys, I didn't notice this issue until now. I will investigate and get back to you. The meta file does not claim to support Ubuntu 16.04 though. But I may be able to quickly add support for it.

@hbokh, could you please give more detail on the problem you encountered on CentOS 7? It will help a great deal with troubleshooting.

hbokh commented 7 years ago

Sorry, but in the meantime I tried ferrarimarco.docker instead. I gave your new code a quick try but ran into this:

TASK [wunzeco.docker : Add docker yum repository config] ***********************
Saturday 19 November 2016  15:31:43 +0100 (0:00:00.092)       0:00:04.920 *****
fatal: [linux002]: FAILED! => {"changed": true, "failed": true, "msg": "Destination /etc/yum.repos.d not writable"}

Don't have time to dive deeper into this. It's pretty easy to test for yourself on a CentOS 7 VM.

wunzeco commented 7 years ago

@hbokh

Thanks for your response. This role has kitchen integration tests to test convergence on a Centos 7 VM. Unfortunately, I'm unable to replicate the issue you observed.

13:48 $ kitchen verify smanager-centos
-----> Starting Kitchen (v1.4.2)
-----> Verifying <smanager-centos-72>...
       Preparing files for transfer
-----> Busser installation detected (busser)
       Installing Busser plugins: busser-serverspec
       Plugin serverspec already installed
       Removing /tmp/verifier/suites/serverspec
       Transferring files to <smanager-centos-72>
-----> Running serverspec test suite
       /opt/chef/embedded/bin/ruby -I/tmp/verifier/suites/serverspec -I/tmp/verifier/gems/gems/rspec-support-3.5.0/lib:/tmp/verifier/gems/gems/rspec-core-3.5.4/lib /opt/chef/embedded/bin/rspec --pattern /tmp/verifier/suites/serverspec/\*\*/\*_spec.rb --color --format documentation --default-path /tmp/verifier/suites/serverspec

       Package "python-pip"
         should be installed

       Package "docker-engine"
         should be installed

       Package "epel-release"
         should be installed

       File "/etc/systemd/system/docker.service.d/docker.conf"
         should be file
         should be mode 644

       File "/etc/logrotate.d/docker-container-logs"
         should be file
         should be mode 644

       Command "docker-compose -h"
         exit_status
           should eq 0

       User "ogonna"
         should belong to group "docker"

       Docker container "swarm-manager"
         should be running

       Docker image "swarm:1.2.5"
         should exist

       Finished in 0.3191 seconds (files took 0.28998 seconds to load)
       11 examples, 0 failures

       Finished verifying <smanager-centos-72> (0m2.65s).
-----> Kitchen is finished. (0m3.05s)
wunzeco commented 7 years ago

@pangdudu

I have update the role to support Ubuntu 16.04. Specifically, it will create supplementary config for docker.service to make your docker options (docker_opts) available to docker engine daemon.

Here is a docker process BEFORE 16.04 support was added

root@smanager-ubuntu-1604:~# ps -ef | grep docker
root      2818     1  0 15:58 ?        00:00:00 /usr/bin/dockerd -H fd://
root      2823  2818  0 15:58 ?        00:00:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime docker-runc
root      3039  2818  0 15:58 ?        00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3375 -container-ip 172.17.0.2 -container-port 2375
root      3046  2823  0 15:58 ?        00:00:00 docker-containerd-shim 2ef9563c2d74cb56b908c1302a83ae412fe3dfd3c97fc25cbb56e23095302422 /var/run/docker/libcontainerd/2ef9563c2d74cb56b908c1302a83ae412fe3dfd3c97fc25cbb56e23095302422 docker-runc
root      3406  3180  0 16:27 pts/1    00:00:00 grep --color=auto docker

Here is a docker process AFTER 16.04 support was added

root@smanager-ubuntu-1604:~# ps -ef | grep docker
root      4328     1  0 16:27 ?        00:00:00 dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
root      4337  4328  0 16:27 ?        00:00:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime docker-runc
root      4449  4328  0 16:27 ?        00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3375 -container-ip 172.17.0.2 -container-port 2375
root      4457  4337  0 16:27 ?        00:00:00 docker-containerd-shim 2ef9563c2d74cb56b908c1302a83ae412fe3dfd3c97fc25cbb56e23095302422 /var/run/docker/libcontainerd/2ef9563c2d74cb56b908c1302a83ae412fe3dfd3c97fc25cbb56e23095302422 docker-runc
root      4616  3180  0 16:28 pts/1    00:00:00 grep --color=auto docker

I have successfully tested the role on an instance of Ubuntu 16.04.

It also turns out that you assigned an incorrect value to docker_opts variable.

docker_opts variable requires a list of strings. An example of its usage is given in README

  vars:
    docker_port: 2375
    docker_opts:
      - "-H tcp://0.0.0.0:{{ docker_port }}"
      - "-H unix:///var/run/docker.sock"

Please give the latest update a try and let me know how get on.
Thanks again for reporting the issue.

hbokh commented 7 years ago

@wunzeco

Thank you. The problem I had seems to be resolved indeed.
I started a small, free CentOS 7 server on dply and the playbook ran smooth:

Saturday 03 December 2016  15:28:47 +0100 (0:00:00.012)       0:03:01.138 *****
===============================================================================
wunzeco.docker : Install docker-engine -------------------------------- 123.65s
wunzeco.docker : Install epel-release repository configuration --------- 15.17s
wunzeco.docker : Install docker-compose --------------------------------- 8.56s
wunzeco.docker : Install python-pip ------------------------------------- 6.64s
wunzeco.docker : Add docker yum repository config ----------------------- 4.02s
wunzeco.docker : Restart docker ----------------------------------------- 3.97s
wunzeco.docker : Start docker ------------------------------------------- 3.86s
wunzeco.docker : Create docker service supplementary config file -------- 3.59s
wunzeco.docker : Install docker api client ------------------------------ 3.40s
setup ------------------------------------------------------------------- 2.74s
wunzeco.docker : Reload systemd if docker service supplementary config file changes --- 1.79s
wunzeco.docker : Create directory for docker service supplementary config --- 1.63s
wunzeco.docker : Reload systemd ----------------------------------------- 1.57s
wunzeco.docker : Install docker ----------------------------------------- 0.28s
wunzeco.docker : debug -------------------------------------------------- 0.05s
wunzeco.docker : Add users to docker group ------------------------------ 0.05s
wunzeco.docker : Get cmd config of currently running swarm-manager container --- 0.02s
wunzeco.docker : Set desired state of swarm-manager docker container ---- 0.02s
wunzeco.docker : Start swarm -------------------------------------------- 0.01s
wunzeco.docker : debug -------------------------------------------------- 0.01s

One more thing: docker_compose_binary: /usr/local/bin/docker-compose from defaults/main.yml seems to be unused in the code and compose will always end up in /usr/bin/ ...

Anyway, merry christmas! :christmas_tree: :santa:

wunzeco commented 7 years ago

@hbokh Thanks for the feedback. I'm glad the role now works for you. Thanks also for pointing out the unused variable (docker_compose_binary). I got rid of it.