Home > Blockchain >  How can I run a docker container in ansible?
How can I run a docker container in ansible?

Time:10-06

This is my yml file

- name: Start jaegar daemon services
  docker: 
    name: jaegar-logz
    image: logzio/jaeger-logzio:latest
    state: started
    env:
      ACCOUNT_TOKEN: {{ token1 }}
      API_TOKEN: {{ token2 }}
    ports:
    - "5775:5775"
    - "6831:6831"
    - "6832:6832"
    - "5778:5778"
    - "16686:16686"
    - "14268:14268"
    - "14250:14250"
    - "9411:9411"

- name: Wait for jaegar services to be up
  wait_for: delay=60 port=5775
  • Can ansible discover the docker image from the docker hub registry by itself?
  • Does this actually start the jaegar daemons or does it just build the image? If it's the latter, how can I run the container?

The docker image is from here - https://hub.docker.com/r/logzio/jaeger-logzio

CodePudding user response:

Assuming you are using docker CE.

You should be able to run according to this documentation from ansible. Do note however; this module is deprecated in ansible 2.4 and above as the documentation itself dictates. Use the docker_container task if you want to run containers instead. The links are available in said documentation link.

As far as your questions go:

Can ansible discover the docker image from the docker hub registry by itself?

This would depend on the client machine that you will run it on. By default, docker will point to it's own docker hub registry unless you specifically log in to another repository. If you use the public repo (which it looks like in your link) and the client is able to go out online to said repo you should be fine.

Does this actually start the jaegar daemons or does it just build the image? If it's the latter, how can I run the container?

According to the docker_container documentation you should be able to run the container directly from this task. This would mean that you are good to go. P.S.: The image parameter on that page tells us that:

Repository path and tag used to create the container. If an image is not found or pull is true, the image will be pulled from the registry. If no tag is included, 'latest' will be used.

In other words, with a small adjustment to your task you should be fine.

  • Related