简体   繁体   中英

docker-compose keep container running after run entrypoint

My docker-compose.yml

version: '3.1'
services:
    redis:
      container_name: redis
      image: redis:3.0
    app_prod:
      container_name: app_prod
      build:
        dockerfile: .docker/app/prod.Dockerfile
        context: ./../
      ports:
          - "8080:80"
      links:
        - mysql:mysql
        - redis:redis
      depends_on:
        - mysql
        - redis
      environment:
        PRODUCTION_MODE: 'true'
      entrypoint: .docker/app/sh/entry-point.sh
    mysql:
      image: mysql
      command: --default-authentication-plugin=mysql_native_password
      restart: always
      environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE: 'my-db'
      build:
        context: ./mysql # path to folder containing Dockerfile

My .docker/app/sh/entry-point.sh

#!/usr/bin/env bash
set -e # exit script if any command fails (non-zero value)
echo Waiting for redis service start...;

while ! nc -z redis 6379;
do
sleep 1;
done;

echo Waiting for mysql service start...;

while ! nc -z mysql 3306;
do
sleep 1;
done;
echo Connected!;

php www/index.php orm:schema-tool:update --force

exec "$@"

I am building by command:

docker-compose -f .docker/docker-compose-prod.yml up -d --build

All containers are built successfully but at the end is running entrypoint script of container app_prod ( .docker/app/sh/entry-point.sh ). Entry point script was processed successfully too but after execute entrypoint script is app_prod container stopped.

It is some way to keep container running?

Thanks

Definitionally, no: once the entrypoint exits the container exits.

Your entrypoint is a shell script ending in exec "$@" (good!) which means that, after it successfully waits for its databases to be up, it will run whatever is passed in the docker-compose.yml as command: . (Note that if you declare entrypoint: in docker-compose.yml , it ignores a CMD in the Dockerfile .) So you just need a command: that starts your service and you should be set

entrypoint: .docker/app/sh/entry-point.sh
command: php-fpm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM