Docker-Compose to create Lamp with phpunit

Asked

Viewed 319 times

0

I am trying to use Docker-Compose to create a LAMP environment along with phpunit to run php TDD and what I intend to do is the following:

  • run a mysql image 5;

  • run a phpunit image 5;

  • run a php 5.6 image so that it communicates with the other images;

  • Run php systems by the browser and be able to run phpunit tests in a terminal;

My Docker-Compose is like this:

version: '2'

services:
  mysql:
    image: mysql:5
    expose:
      - "3306"
    environment:
      MYSQL_ROOT_PASSWORD: 12345
      MYSQL_DATABASE: lamp-teste

  php-unit:
      image: phpunit/phpunit:5.7.12

  php-5.6:
    image: php:5.6
    ports:
      - 8080:80
    volumes:
      - ./log/apache2/error.log:/var/log/apache2/error.log
      - ./log/apache2/access.log:/var/log/apache2/access.log
      - ./html:/var/www/html
    environment:
      WORDPRESS_DB_HOST: mysql
      WORDPRESS_DB_USER: root
    depends_on:
      - mysql
      - php-unit

After running the file with the Docker-Compose up -d command appears this:

Recreating dockerlampteste_mysql_1 ... 
Recreating dockerlampteste_php-unit_1 ... 
Recreating dockerlampteste_php-unit_1
Recreating dockerlampteste_mysql_1 ... done
Recreating dockerlampteste_php-5.6_1 ... 
Recreating dockerlampteste_php-5.6_1 ... done

And when executing the command "Docker-Compose ps" appears this:

Name                         Command             State     Ports  
----------------------------------------------------------------------
dockerlampteste_mysql_1      docker-entrypoint.sh mysqld     Up       
3306/tcp
dockerlampteste_php-5.6_1    docker-php-entrypoint php -a    Exit 0           

dockerlampteste_php-unit_1   /usr/local/bin/phpunit --help   Exit 0 

And when executing the command "Docker ps" it appears that only the mysql image is being executed.

Apparently only mysql is running and php and phpunit is not, what is wrong and how can I after running everything run phpunit by terminal ?

  • Friend try to see why the container is being finished, try docker logs dockerlampteste_php-5.6_1 and docker logs dockerlampteste_php-5.6_1. I would also suggest naming the containers to make the job easier, see a nice template here: https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion

  • I ran the log, it appeared this msg: (21)Is a directory: AH00091: apache2: could not open error log file /var/log/apache2/error.log. AH00015: Unable to open logs Gotta set a location for logs ? How do I do ?

  • remove your logs and try again: - ./log/apache2/error.log:/var/log/apache2/error.log
 - ./log/apache2/access.log:/var/log/apache2/access.log

  • I tried without the logs and gave error, I tried setting only the directory for the logs and was still in it, I decided to change the image of php to php:5.6-apache and it worked.

  • 1

    ah yes to php:5.6 uses Nginx. blz

1 answer

0


I changed the php image and the volume to apache logs, so Docker-Compose.yml:

version: '2'

services:
  mysql:
    image: mysql:5
    expose:
      - "3306"
    environment:
      MYSQL_ROOT_PASSWORD: 12345
      MYSQL_DATABASE: lamp-teste

  php-unit:
      image: phpunit/phpunit:5.7.12

  php-5.6:
    image: php:5.6-apache
    ports:
      - 8080:80
    volumes:
      - ./log/apache2:/var/log/apache2
      - ./html:/var/www/html
    depends_on:
      - mysql
      - php-unit

Browser other questions tagged

You are not signed in. Login or sign up in order to post.