I tried to install it in Dockerfile
FROM python:3.7-slim-stretch
RUN apt-get update && apt-get install -y \
ssh \
sshpass \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /tmp
COPY requirements.txt /tmp
RUN pip install -r requirements.txt && rm requirements.txt
RUN groupadd --gid 1001 ansible && useradd --uid 1001 --gid 1001 -m ansible
COPY ansible.cfg /home/ansible/.ansible.cfg
RUN mkdir -p /home/ansible/.ansible/roles/ && chown -R ansible:ansible /home/ansible/
COPY requirements.yml /home/ansible/requirements.yml
RUN ansible-galaxy install -r /home/ansible/requirements.yml
WORKDIR /playbook
USER ansible
requirements.txt
ansible==3.2.0
requirements.yml
- src: geerlingguy.php
ansible.cfg
[defaults]
roles_path = ~/.ansible/roles
I start docker with docker-compose. The config file is
version: "3.8"
services:
ansible:
build:
context: ./ansible
dockerfile: Dockerfile
image: ansible
container_name: ansible
hostname: ansible
#command: ['/bin/bash', '-c', 'ansible-galaxy install -r ./playbook/requirements.yml']
tty: true
volumes:
- ./playbook:/playbook
- ./roles:/home/ansible/.ansible/roles/
In the build step I can see ansible-galaxy installed roles that defined in the requirements.yml
file.
But when I login into the container ansible
, I can’t find the roles at all.
If I remove the two lines from Dockerfile, add command
way in the docker-compose.yml file, after build, I can’t login into the container. There was an error
Error response from daemon: Container 11111111111111111111111111111111111111111111111111111111111 is not running
I’m confused why they weren’t been installed in the image if set the install action in Dockerfile?