0

I'm dockerizing lemp stack with following docker-compose config:

mariadb:
 container_name: lemp-mariadb
 image: mariadb
 #user: $UID
 environment:
  - MYSQL_ROOT_PASSWORD=root.maria
  - MYSQL_DATABASE=wordpress
  - MYSQL_USER=wordpress
  - MYSQL_PASSWORD=wordpress
 volumes:
  - ./db:/var/lib/mysql
phpfpm:
 container_name: lemp-fpm
 image: php:7-fpm
 volumes:
  - ./code:/code
 links:
  - mariadb
 command: docker-php-ext-install mysqli
nginx:
 container_name: lemp-nginx
 image: nginx:latest
 ports:
  - "8080:80"
 volumes:
  - ./code:/code
  - ./site.conf:/etc/nginx/conf.d/default.conf
 links:
  - phpfpm
 command: nginx -g 'daemon off;'

Problem lies with with line in config:

command: docker-php-ext-install mysqli

If I comment this line during docker-compose up routine, it runs fine leaving 3 of the machines running, All I have to do is run this command on lemp-fpm machine via docker exec like this:

docker exec lemp_phpfpm_1 docker-php-ext-install mysqli

which gives no error and I can connect to database with mysqli extension. The lemp-fpm instance quits with 0 erro code when same command runs via docker-compose. The question is why? and what's the work-around?enter image description here

Qwertie
  • 16,354
  • 20
  • 105
  • 148
Sollosa
  • 379
  • 4
  • 13

1 Answers1

0

Docker containers are meant to exit once the "command" specified has completed. If you want the container to stay around after the command has completed, give some other command in addition, like a tail command that stays open.

Your other alternative is to run your "docker-php-ext-install mysqli" during docker image build time and build your own container image. Then run the container with just a "tail -f /dev/null" as the "command" line.

sxm1972
  • 722
  • 8
  • 15
  • @sxsm1972 you mean I have to start it docker-compose like this? docker-compose up -d – Sollosa May 06 '19 at 05:57
  • No. Change your command line to: `command: docker-php-ext-install mysqli && tail -f /dev/null` That way the tail command will keep running indefinitely and hence prevent your container from exiting. – sxm1972 May 06 '19 at 10:26
  • 1
    See the comments in this [post](https://stackoverflow.com/questions/30209776/docker-container-will-automatically-stop-after-docker-run-d) for an explanation of what is happening. – sxm1972 May 06 '19 at 10:30