0

I've got a very strange issue here, and i am not sure what i am doing wrong, must be something simple but i just cannot figure it out.

My docker-compose.yml:

mysql:
  image: mysql:5.7
  container_name: mysql
  environment:
    - MYSQL_ROOT_PASSWORD=aaa
    - MYSQL_DATABASE=aaa
    - MYSQL_USER=aaa
    - MYSQL_PASSWORD=aaa
    - MYSQL_PORT=3306
    - MYSQL_HOST=localhost

php-fpm:
  build: .
  dockerfile: php-fpm/Dockerfile
  container_name: php-fpm
  volumes:
    - ../app:/var/www/html
  links:
    - mysql
  environment: 
    PHP_php5enmod: 'bcmath gd gmp intl mbstring mysql mysqli pcntl pdo_mysql redis zip sockets'

caddy:
  build: .
  dockerfile: caddy/Dockerfile
  container_name: caddy
  volumes:
      - ../app:/var/www/html
      - ./caddy/Caddyfile:/etc/Caddyfile
      - ./caddy/certs:/root/.caddy
  ports:
   - "80:80"
   - "443:443"
  links:
   - mysql
   - php-fpm

The Dockerfile for php-fpm:

FROM alterway/php:7.1-fpm

# update
RUN apt-get update && apt-get install -y bash zip unzip

# require the asset plugin
RUN composer global require "fxp/composer-asset-plugin:^1.3.1"

# copy the entrypoint
COPY ./php-fpm/docker-entrypoint.sh /root/docker-entrypoint.sh

# setup permissions
RUN chmod +x /root/docker-entrypoint.sh

# Clean up, try to reduce image size (much as you can on Debian..)
RUN apt-get autoremove -y \
    && apt-get clean all \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /usr/share/doc /usr/share/man /usr/share/locale

ENTRYPOINT ["/root/docker-entrypoint.sh"]

( if i comment out the ENTRYPOINT the container starts just fine )

And in my docker-entrypoint.sh file, i am just trying to run a migration:

#!/bin/bash

# run the migration
/var/www/html/yii migrate/up --interactive=0 --migrationPath=/var/www/html/vendor/twisted1919/yii2-options/migrations

So all i want to do is to run a shell script right after the container starts, but nothing seems to work.

Another thing, if i comment out the ENTRYPOINT in my Dockerfile, while the container starts and executes the database migration, it complaints it does not find a valid mysql driver, but if i login in the container and try to run the migration manually, then it works just fine, so maybe something is wrong with alterway/docker-php

1
  • I think the issue here is that MYSQL is not ready to accept connections when the php-fpm container tries to run the migrations. I'm still investigating. Commented May 3, 2017 at 10:36

2 Answers 2

1

Ok, so the issue was indeed the fact mysql was not ready for connections. I didn't went for a health check thing, i simply wrapped all in a shell script to start/stop/restart docker-compose and also to call the scripts i need inside the container, it's way easier this way.

Sign up to request clarification or add additional context in comments.

Comments

0

I think adding a health check may help you out.

This way you can tell docker-compose to wait for mysql to be healthy before starting php-fpm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.