ansible equivalent of docker run "-c"

to run a docker postgres container with custom config you would use a command like this:

"docker container run -d postgres -c max_connections=6 -c log_lock_waits=on"

i have the task as:

name: Start postgis
  become: true
  docker_container:
    name: postgis
    image: "{{ ecr_url }}"    
    network_mode: bridge
    exposed_ports:
      5432
    published_ports:
      5432:5432
    state: started
    volumes:
    - /mnt/datadir/pgdata:/var/lib/postgresql/data

which will indeed run the container, but then my question is:

what is the equivalent in asible of the "-c" flag in the docker run command??


thanks larsks for the answer, you can send multiple commands one below the other

published_ports:
      5432:5432
    state: started
    command:
      -c shared_buffers = 24000MB
      -c work_mem=16MB
      -c maintenance_work_mem = 128MB
      -c etcetera

Upvotes: 3

Views: 2046

Answers (1)

larsks
larsks

Reputation: 312018

Remember that the syntax for the docker run is:

docker run [...docker options...] image [...command and args...]

With that in mind, look at your command line:

docker container run -d postgres -c max_connections=6 -c log_lock_waits=on

Those -c arguments come after the image name, so they are not flags to docker run. They are instead part of the command being passed into the container and in this case they end up being arguments to the postgres command.

So in Ansible, you would just have:

docker_container:
  name: postgis
  image: "{{ ecr_url }}"    
  command: "-c max_connections=6 -c log_lock_waits=on"

Upvotes: 5

Related Questions