Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_service causes failure with user option docker-compose.yml #25943

Closed
mchassy opened this issue Jun 21, 2017 · 9 comments
Closed

docker_service causes failure with user option docker-compose.yml #25943

mchassy opened this issue Jun 21, 2017 · 9 comments
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bot_closed bug This issue/PR relates to a bug. cloud collection:community.general collection Related to Ansible Collections work docker module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community.

Comments

@mchassy
Copy link

mchassy commented Jun 21, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_service

ANSIBLE VERSION
ansible 2.3.1.0
  config file =
  configured module search path = Default w/o overrides
  python version = 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
(venv2)
CONFIGURATION

No specific config

OS / ENVIRONMENT
Client - Running ansible form a Mac (10.12.5)
Host - Provisioning a RHEL7 server 
Red Hat Enterprise Linux Server release 7.3 (Maipo)
Docker version 17.03.1-ce, build c6d412e
docker-compose version 1.13.0, build 1719ceb
base docker image: ansible/centos7-ansible which is then running
ansible 2.2.0.0
  config file =
  configured module search path = Default w/o overrides
SUMMARY
  • After building 2 images using the docker_image module, I want then run container based on those images using a docker-compose.yml file and the docker_service module. By default all containers run as root. Running the containers in the is way works fine.
  • But there is a user option in docker-compose to run the containers as a different user. I create this user during the build process. Then I put the user option into the docker-compose file.
  • If I do this, and run the playbook using docker_service, one of the containers (always the same) fails to run correctly.
  • As a sanity check, I ran docker-compose using the command module and it works fine and I went on the server and ran docker-compose manually and it works fine.
  • As a final note, this would also be a nice new functionality to have the user option directly in the docker_service module
STEPS TO REPRODUCE
build images 
   - name: Build the orson_app image based on ansible
      docker_image:
        path: "{{ host_tomee_container }}"
        name: "orson_app"
        state: "present"
        force: "yes"
      register: orson_app_result
    - name: Build the orson_db image based on ansible
      docker_image:
        path: "{{ host_mongo_container }}"
        name: "orson_db"
        state: "present"
        force: "yes"
      register: orson_db_result
Run services 
    - name: build and start both containers in compose style
      docker_service:
        state: "present"
        build: "yes"
        project_src: "{{ host_home }}"
        project_name: "orson"
        recreate: "always"
        # restarted: "yes"
      async: 300
      poll: 5
OR
Execute docker-compose
    - name: Run docker-compose as a command
      command: "docker-compose up -d --build"

I will upload the full set of playbooks, Dockerfiles, and docker-compose.yml files which are in this hierarchy
Level 1 - Host level

  • orson-host.yml - provisions server with docker, docker-compose, etc and places all the files necessary to build the images.
  • This level also includes the docker-compose file.

Level 2 - Service level (for each service)

  • Dockerfile
  • vars.yml
  • playbook.yml

Sorry, my project is bitbucket not github, so I can't share gists. I will have to rename and upload files.

  • Uploaded files (renamed to .txt)
  • host playbook (orson-host.yml.txt) -- this contains both the docker_service lines and the command lines. Of course, only one set of lines would be run. I included both to show both solutions. Also, most of lines are commented out for the moment, to show just what is important.
  • docker-compose.yml.txt
  • 2 service Dockerfiles (renamed per service for clarity)
  • 2 service playbooks (renamed per service for clarity)

orson-host.yml.txt
docker-compose.yml.txt
Dockerfile.mongo.txt
Dockerfile.tomee.txt
playbook.yml.tomee.txt
playbook.yml.mongo.txt

EXPECTED RESULTS

Both containers run with primary process running as orson user instead of root.

ACTUAL RESULTS

Client side ansible script results

~/github/ansible_docker
$ ./play.sh

PLAY [common] *******************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************
ok: [orson-server]

TASK [Load Variables] ***********************************************************************************************************************************************************************
ok: [orson-server]

TASK [copy docker-compose to /home/ec2-user] ************************************************************************************************************************************************
ok: [orson-server]

TASK [Ensure mode on all synched files] *****************************************************************************************************************************************************
ok: [orson-server]

TASK [build and start both containers in compose style] *************************************************************************************************************************************
changed: [orson-server]

PLAY RECAP **********************************************************************************************************************************************************************************
orson-server               : ok=5    changed=1    unreachable=0    failed=0

(venv2)

Host side docker results if docker_service is used (Exited 100 on mongo just means unhandled exception)

[root@ip-172-31-42-225 ec2-user]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS                    NAMES
9e8a23200bb8        orson_app:latest    "./catalina.sh run"      3 minutes ago       Up 3 minutes                 0.0.0.0:8080->8080/tcp   orson_app_container
0a22f59b0d21        orson_db:latest     "/bin/sh -c './mon..."   3 minutes ago       Exited (100) 3 minutes ago                            orson_db_container

If command: docker-compose up -d is used

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
ce4995dddb57        orson_app:latest    "./catalina.sh run"      8 seconds ago       Up 7 seconds        0.0.0.0:8080->8080/tcp   orson_app_container
1dde4fb8fd1a        orson_db:latest     "/bin/sh -c './mon..."   8 seconds ago       Up 7 seconds        27017/tcp                orson_db_container
@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report cloud docker module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Jun 21, 2017
@mchassy
Copy link
Author

mchassy commented Jun 21, 2017

As an additional way of doing things, I used the USER instruction in my Dockerfile (which is probably the better way anyway).
Again the same result, the 2 images build correctly and the 2 containers come up correctly using
command: docker-compose up -d
But when the same is done with the docker_service module, the mongo container always fails.

@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Jun 21, 2017
@ansibot ansibot added the support:community This issue/PR relates to code supported by the Ansible community. label Jun 29, 2017
@ansibot
Copy link
Contributor

ansibot commented Jul 18, 2017

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@ansibot
Copy link
Contributor

ansibot commented Oct 4, 2018

@ansibot
Copy link
Contributor

ansibot commented Nov 2, 2018

@ansibot
Copy link
Contributor

ansibot commented Dec 12, 2018

@felixfontein
Copy link
Contributor

Please note that the docker_service module will be renamed to docker_compose in Ansible 2.8. You will be able to still use the old name, but you will receive a warning when doing so.

!component =lib/ansible/modules/cloud/docker/docker_compose.py

Also, please note that currently, nobody is actively maintaining the Ansible docker_service/docker_compose modules. If you are interested in working on this issue, please feel free to create a PR :) If you need any help, feel free to ping me or any other of the current docker_* module maintainers.

@ansibot
Copy link
Contributor

ansibot commented Feb 4, 2019

@ansibot
Copy link
Contributor

ansibot commented Apr 9, 2019

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. labels Apr 17, 2019
@ansibot ansibot added module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 25, 2019
@ansibot ansibot added collection Related to Ansible Collections work collection:community.general needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Apr 29, 2020
@ansibot
Copy link
Contributor

ansibot commented Aug 17, 2020

Thank you very much for your interest in Ansible. Ansible has migrated much of the content into separate repositories to allow for more rapid, independent development. We are closing this issue/PR because this content has been moved to one or more collection repositories.

For further information, please see:
https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md

@ansibot ansibot closed this as completed Aug 17, 2020
@ansible ansible locked and limited conversation to collaborators Sep 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bot_closed bug This issue/PR relates to a bug. cloud collection:community.general collection Related to Ansible Collections work docker module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

No branches or pull requests

4 participants