Kevin
Kevin

Reputation: 5092

Docker - Execute a bash when running a container

I have this part of my docker-compose file:

php-fpm:
    build: ./docker/php
    container_name: php-fpm-symfony
    links:
        - db
    ports:
        - 9000:9000
        - 8448:8448
        - 8000:8000
    working_dir: /var/www/html/
    volumes:
        - .:/var/www/html
    volumes_from:
        - data
    tty: true
    env_file:
        - ./docker.env
    entrypoint: /command.sh

And here is my Dockerfile:

FROM php:7.0.8-fpm
ADD command.sh /command.sh
RUN chmod 777 /command.sh
ENTRYPOINT ["/command.sh"]

My command.sh at the root

#!/usr/bin/env bash
git config --global user.email "${gitEmail}"
git config --global user.name "${gitName}"

I need to execute my command.shfile when I'm doing my docker-compose up -d

But it does not work that way.

ERROR: for nginx Cannot link to a non running container: /php-fpm-symfony AS /nginx/php-fpm ERROR: Encountered errors while bringing up the project. Error response from daemon: Container 7c2a9bffa9664c4007d685f56d17e4659c6dd7021962d6462177480f5a821d44 is not running

How can I make this work?

Upvotes: 0

Views: 1300

Answers (1)

Camilo Silva
Camilo Silva

Reputation: 8721

A docker container exits when its main process finishes.

Your script is certainly finishing and no php process is launched. Try adding a call to php-fpm

#!/usr/bin/env bash
git config --global user.email "${gitEmail}"
git config --global user.name "${gitName}"
php-fpm

Upvotes: 3

Related Questions