docker-library / percona

DEPRECATED Docker Official Image packaging for Percona Server, new repo:
https://github.com/percona/percona-docker/
Apache License 2.0
51 stars 70 forks source link

docker-compose and docker-entrypoint-initdb.d sql import not working #33

Closed magextrem closed 6 years ago

magextrem commented 7 years ago

Hi there,

I'm triing to populate my database with the docker-entrypoint-initdb.d directory but each time I try to compose, it's not triggered.

Here's a copy of my docker-compose.yml :

db:
  image: percona:5.6
  labels:
    io.rancher.container.pull_image: always
    io.rancher.scheduler.affinity:host_label_soft: io.blackcreeper.com.server=mysql
  volumes:
    - /var/lib/mysql
    - /private/var/www/dumps/maparfumerie:/docker-entrypoint-initdb.d
  restart: always
  environment:
    MYSQL_ROOT_PASSWORD: root
    MYSQL_DATABASE: test
    MYSQL_USER: root
    MYSQL_PASSWORD: root
magento:
  image: magextrem/php-apache:5.4
  links:
    - db
  volumes:
    - /private/var/www/html/test:/var/www/html
  environment:
    - VIRTUAL_HOST=www.test.local

The magextrem/php-apache:5.4 is a custom build. I checked in the docker container created an the file test.sql was in /docker-entrypoint-initdb.d, so I don't understand why the database isn't populated. I've already tried to delete both the container and the image to pull it again but without success.

I'm certainly missing something, can you help me figure out this ?

Thanks,

Kevin

yosifkit commented 7 years ago

Did you start it once and then add or change the environment variables or the init script? This explanation on the postgres image might help: https://github.com/docker-library/postgres/issues/203#issuecomment-255200501. Any scripts in the initdb directory are only run on first initialization, so if the db files exist then the scripts never run.

magextrem commented 7 years ago

Thanks for your help yosifkit,

I tried to delete containers, volumes and images but it didn't work.

So I restarted everything with a minimal docker-compose.yml and added step by step customizations. My problem was the 2 following lines :

    MYSQL_USER: root
    MYSQL_PASSWORD: root

Indeed when I added them, my database wasn't populated. I think these 2 lines caused conflict with MYSQL_ROOT_PASSWORD: root and stopped the initdb process ...

tianon commented 7 years ago

Ah, yeah, setting MYSQL_USER to root doesn't really make sense -- we always create a root user, and MYSQL_USER is specifically for creating an additional user. :confused:

onigirisan commented 5 years ago

@magextrem OMG! You really save my live, thank you dear!

swastikasinghal commented 5 years ago

@yosifkit Can you help me too please?

This is my docker-compose.yml:

version: '3'

services:
  dbpostgres:
      image: postgres
      restart: on-failure
      environment:
        POSTGRES_PASSWORD: 'postgres'
        POSTGRES_USER: 'docker'
        POSTGRES_PASSWORD: 'hello'
      volumes:
        - ./schema.sql:/docker-entrypoint-initdb.d/init.sql
      ports:
        - '5432:5432'
      expose:
        - '5432'
  dbmysql:
      image: mysql:5.7
      restart: on-failure
      environment:
        MYSQL_ROOT_PASSWORD: 'mysql'
        MYSQL_DATABASE: 'rb_krux'
        MYSQL_USER: 'docker'
        MYSQL_PASSWORD: 'hello'
      volumes:
        - ./latest.sql:/docker-entrypoint-initdb.d/init.sql
      ports:
        - '3306:3306'
      expose:
        - '3306'
  web:
    depends_on:
        - 'dbpostgres'
        - 'dbmysql'
    build: .
    environment:
      LOCAL_SETTINGS: 'app.local_settings'
      ENVIRONMENT_VAR_PATH: '/host_home/.console.env'
      RDS_HOSTNAME: 'dbmysql'
      RDS_USER: 'docker'
      RDS_PASS: 'hello'
      RDS_PORT: '3306'
      RDS_DB_NAME: 'rb_krux'
      REDSHIFT_REPORTS_HOSTNAME: 'dbpostgres'
      REDSHIFT_REPORTS_PORT: '5432'
      REDSHIFT_REPORTS_USER: 'docker'
      REDSHIFT_REPORTS_PASS: 'hello'
      REDIS_HOST: 'redis'
    working_dir: /dataconsole_docker/console
    links:
      - dbmysql
      - dbpostgres
      - redis
    command: /dataconsole_docker/startup.bash
    volumes:
      - .:/dataconsole_docker
      - ~:/host_home
    ports:
      - '38080:8080'  # Map port 38080 on host to 8080 in container
  redis:
      image: "redis"

I followed your instructions to remove everything before building an image using the following commands:

docker system prune -a

docker system prune --volumes

Even then, the init.sql for both databases doesn't seem to work.

tianon commented 5 years ago

Please direct support requests to the Docker Community Forums, the Docker Community Slack, or Stack Overflow.