お首が長いのよお首が長いのよ

チラシの裏よりお届けするソフトウェアエンジニアとして成長したい人のためのブログ

2018-09-05

How to use docker-php-ext-install command on the docker_container of ansible modules.

I faced any problems that is couldn't use command option of a docker_container module.

I need customize php-fpm container, so I used command in docker_container's command option. But I had any struggle points.

My struggles..

  1. I didn't recognize command option's reference detail. Is parameter type string? list?  fmm??
  2. Importance of ENTRYPOINT(docker-php-entrypoint?? what's this?)
  3. In using **command option,**Docker container shutting down immediately.
    • PHP-fpm container is uses exposed port. Why shutting down????

How to

Let me get straight the point, this playbook is a my solution.

yaml
1- name: Deploy PHP7 on docker container
2    docker_container:
3      name: php7-fpm
4      auto_remove: yes
5      command: [
6        "bash",
7        "-c","
8        'apt update && apt install zlib1g-dev && docker-php-ext-install zip && docker-php-ext-install pdo_mysql && php-fpm'"
9      ]
10      image: php:7-fpm
11      exposed_ports:
12        - 9000
13      state: started
14

Answer of my struggles

 1.

A command option of docker_container can receive one of shell command.

["ping","127.0.0.1","-c","5"]

"ping 127.0.0.1 -c 5"

Both styles can use too.

2.

"docker-php-entrypoint" distinguish argument's -

If entrypoint option and command option that both have a some parameter, Executing that the command option is option of entrypoint's.

3.

PHP7-fpm docker container runs php-fpm shell command on the command that is equivalent of dockerfile's CMD directive. However, my wrong playbook didn't have php-fpm command at last. Therefore all commands successfully done, and container shutting down.

yaml
1command: [
2        "bash","-c","'apt update && apt install zlib1g-dev && docker-php-ext-install zip && docker-php-ext-install pdo_mysql"
3      ]
4

So, bash commands option helped my solution.

"/bin/bash -c '{any commands of combined from &&}'"

Please your advices, comments.

thanks.

よかったらシェアしてください!