Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass command line arguments to Docker with Ansible

I have a Java socket application that requires a port number as a CLI argument. On my local machine I can run it via:

docker run -d -p 1111:1111 --name <name> --link <link> <foo>/<bar> 1111

The problem is that I haven't found a solution to pass the port number when using Ansible (I have a different task that pulls the image). Current task:

- name: Run server
      docker:
          name: <name>
          image: <foo>/<bar>
          state: reloaded
          ports:
              - "1111:1111"
          links:
              - "<link>"

Is there a way to pass the port as a CLI argument? Or is there a simple way to work around this? I've though about uploading a new image or using the command module but neither seem like right way to go.

like image 243
tomtomssi Avatar asked Feb 21 '16 18:02

tomtomssi


2 Answers

There is no native support to pass arbitrary arguments in Ansible's Docker module. See passing extra args to docker: task.

Can't you use shell module to achieve what you want?

like image 157
helloV Avatar answered Sep 23 '22 05:09

helloV


If you can change the image I would recommend to use environment vars instead . That's supported by the docker module.

- name: Run server
  docker:
    name: <name>
    image: <foo>/<bar>
    state: reloaded
    ports:
      - "1111:1111"
    links:
      - "<link>"
    env:
      MY_PORT: 1111
like image 22
udondan Avatar answered Sep 26 '22 05:09

udondan