0

We are able to run the docker container locally with docker file having relative path in ENTRYPOINT:

USER user1

WORKDIR /home/user1

ADD script.sh $HOME/script.sh

ENTRYPOINT ["./script.sh"]

When the same docker image(of above docker file) is launched from ansible tower using below task:

- name: Run docker container
  command: docker run --rm -e arg={{value}} 111122223333.dkr.ecr.us-east-1.amazonaws.com/someteam:v.1

We get file not found error for script.sh

How to resolve this error?

overexchange
  • 15,768
  • 30
  • 152
  • 347
  • Does it work in a less complex environment, for instance directly `docker run` the same image without Ansible? If you get a debug shell in a container based on the image, is the script where you expect? – David Maze Aug 08 '19 at 19:46
  • @DavidMaze yes it runs without ansible – overexchange Aug 08 '19 at 19:48
  • a) you have to quote your command string since it contains a jinja placeholder b) Don't use `command` for this but the [`docker_container` module](https://docs.ansible.com/ansible/latest/modules/docker_container_module.html) – Zeitounator Aug 08 '19 at 22:25
  • @Zeitounator Do you mean somthing like this? `command: "docker run --rm -e arg={{value}} 111122223333.dkr.ecr.us-east-1.amazonaws.com/someteam:v.1"` In debug I see them getting resolved without double quotes – overexchange Aug 08 '19 at 22:34
  • Yes, thats exactly what I mean. Which version of ansible are you using ? It should only be allowed and ^work' with old versions... – Zeitounator Aug 08 '19 at 22:41
  • @Zeitounator ansible 2.3 – overexchange Aug 08 '19 at 22:42
  • That's old. I don't remember exactly but `docker_container` might be called `docker` in that version... And then the var interpolation is not an issue and should not influence the problem you're experiencing. – Zeitounator Aug 08 '19 at 22:46
  • @Zeitounator `docker` module is requiring `pip install docekr-py` which I cannot do – overexchange Aug 09 '19 at 00:40

2 Answers2

1

Change your entrypoint to use the full path to the script:

ENTRYPOINT ["/home/user1/script.sh"]
Matt P
  • 2,452
  • 1
  • 12
  • 15
0

Maybe the Vars {{ playbook_dir }}->Full path to playbook or: {{ role_path}} ->The path to the dir of the currently running role Could help.