Variables in Dockerfile not expanded when run through Ansible’s community.docker.docker_compose

  Kiến thức lập trình

I finally found out, that I need to run the CMD in shell mode, since I have variables in the command line (as stated here : How can I use a variable inside a Dockerfile CMD?)

The CMD in the Dockerfile is:

CMD ["sh", "-c", "gunicorn -w=4 --bind=0.0.0.0:7004 --certfile=/data/cert/${HOSTNAME}.crt --keyfile=/data/cert/${HOSTNAME}.key main:app"]

With this, docker-compose up -d is running fine.

But, when running the same Dockerfile from an Ansible playbook, then the variables are not being expanded. I use the module community.docker.docker_compose.

The log output of the container with the gunicorn startup is:

  # ...
  keyfile: /data/cert/.key
  certfile: /data/cert/.crt
  # ...

Ansible output is

ok: [host.example.com] => {
    "output": {
        "changed": true,
        "failed": false,
        "services": {
            "my_service": {
                "my_service": {
                    "cmd": [
                        "sh",
                        "-c",
                        "gunicorn -w=4 --bind=0.0.0.0:7004 --certfile=/data/cert/${HOSTNAME}.crt --keyfile=/data/cert/${HOSTNAME}.key main:app"
                    ],

How can I convince Ansible to expand these environment variables?

4

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT