0

I have this docker-compose.yml

version: '3'
services:
  wordpress_db:
    restart: unless-stopped
    build: 
      context: ./db
    environment:
      MYSQL_USER: ${WP_DB_USER}
      MYSQL_PASSWORD: ${WP_DB_USER_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${WP_DB_USER_PASSWORD}
      MYSQL_DATABASE: ${WP_DB_NAME}
    ports:
      - 3306:3306

This is my dockerfile

FROM mysql:5.7
COPY ./smartcom_wp_db.sql /docker-entrypoint-initdb.d/smartcom_wp_db.sql

What the weird thing is , I actually got it to work before. All my tables has been created and everything , all was a-ok.

But now after all mocking around.. And rebirthed it back to the above configuration. For some reason only a few tables are now created? I tried removing all the images , containers and recreating the image and container.

What is going on? I have like 33 tables inside the .sql file and now only 11 are being created. Im just pulling my hair out. What could it suddenly not work properly????

Chopnut
  • 607
  • 2
  • 8
  • 25
  • Any suspicious log from mysql container? – Emruz Hossain Nov 21 '18 at 05:04
  • @EmruzHossain I did look at the log, nothing out of ordinary. Just a bunch of initializing text. Seems a bit odd though when I ssh to the container. The mysql service was not running. So I have to manually start it. I dont know if thats intended.. How is was working then suddenly not..driving me nuts.. – Chopnut Nov 21 '18 at 05:07
  • Ah I got it! It was because, the query was taking so long, and the moment I log into the container, it stops the query! And when I show all the tables, it was only showing the ones thats already been created. – Chopnut Nov 21 '18 at 05:22
  • Great to hear that. However, you shouldn't build a new docker image just to put initialization script in `/docker-entrypoint-initdb.d` directory. You can mount a volume with initialization script to that directory. That will give you flexibility to change initialization script easily and you will able to use same docker image in multiple project. – Emruz Hossain Nov 21 '18 at 05:32
  • 1
    Also, if your problem is solved, add an answer explaining what was happening. This might help others. – Emruz Hossain Nov 21 '18 at 05:33
  • 1
    I will thanks Emruz for the tip as well. – Chopnut Nov 21 '18 at 05:36

1 Answers1

0

I figure it out.

From this post: How do I know when my docker mysql container is up and mysql is ready for taking queries?

The query was just taking its sweet time, as there is really no way of knowing when it will be finished. So if you ssh to the mysql container and the query is not finished yet. You will only see whats already been created and not everything.

I actually have an existing wordpress site I want to dockerize. So when I view the wordpress container it would throw a bunch of errors as its looking for a table that is not there yet.

Chopnut
  • 607
  • 2
  • 8
  • 25