1
votes

So, I have the following docker-compose file:

version: "3"

services:
  webserver:
    build: 
      context: ./bin/webserver
    container_name: 'png-webserver'
    restart: 'always'
    ports:
      - "18011:80"
      - "14431:443"
    links: 
      - mysql
    volumes: 
      - ${DOCUMENT_ROOT-./www}:/var/www/html
      - ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
      - ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
      - ${LOG_DIR-./logs/apache2}:/var/log/apache2
  mysql:
    build: ./bin/mysql
    container_name: 'png-mysql'
    restart: 'always'
    ports:
      - "13306:3306"
    volumes: 
      - ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
      - ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
      - ./mysqlhome:/home
    environment:
      MYSQL_ROOT_PASSWORD: tiger
      MYSQL_DATABASE: nubuilder
      MYSQL_USER: deckoff
      MYSQL_PASSWORD: deeppurple
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: 'png-phpmyadmin'
    links:
      - mysql
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
    ports:
      - '18080:80'
    volumes: 
      - /sessions

And the following Dockerfile ( for the mariadb container):

FROM mariadb:10.1

RUN mysql --defaults-extra-file='/home/secret' nubuilder4 < /home/nubuilder4.sql

RUN apt-get update && apt-get install -y nano 

RUN bash -c 'echo [mysqld] >> /etc/mysql/my.cnf'
RUN bash -c 'echo sql-mode=NO_ENGINE_SUBSTITUTION >> /etc/mysql/my.cnf'

In a nutshell - seems like RUN commands in the Dockerfile never run. I would expected the 2 lined appended to the file, and nano installed, but none of this happens. I have tried running them after starting the containers, and they work fine. Seems like I am doing something wrong.

Also, I have no idea how to debug that.

1
What happens when you do run it? Does the MariaDB Dockerfile go with the mysql: block in the docker-compose.yml? - David Maze
Are you actually (re)building the image with docker-compose build? - jwodder
That was it, seems I need to build a new image, I thought that docker-compose up does that as well, seems it just creates the containers and "glues" them together - deckoff

1 Answers

0
votes

RUN commands to install nano and echo lines into files seems correct. Most likely the problem is in RUN mysql --defaults-extra-file='/home/secret' nubuilder4 < /home/nubuilder4.sql

Since you are mounting volume /home, there is no way for us to debug it. Are you sure that this RUN mysql... command passes successfully?

To debug: change your docker-compose.yml, instead of build: ./bin/mysql, use image: mariadb:10.1 and then connect to the container and run the first command with mysql.