0
votes

I have a docker image for mysql datbase.

The first time I made this work I backed up my db to a .sql file and then from my docker-compose I build up the dabase.

Now however I have made some updates, created a new .sql file and again through the docker-compose I thought I would get my new data and new changes.

my docker-comose file:

services:
  mysql:
    image: mysql:latest
    container_name: mysqldb
    cap_add:
      - SYS_NICE # CAP_SYS_NICE
    # container_name: my_very_special_server
    ports:
      - 3307:3306
    environment:
      MYSQL_DATABASE: wedding
      MYSQL_ROOT_PASSWORD: SomeRootPassword1!
      MYSQL_USER: someuser
      MYSQL_PASSWORD: Password1!
    volumes:
      - ./dbScript/Dump20201018.sql:/docker-entrypoint-initdb.d/Dump20201018.sql
      - db_data:/var/lib/mysql
    restart: always
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: dev_pma
    links:
      - mysql
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3307
      PMA_ARBITRARY: 1
    restart: always
    ports:
      - 8183:80
  server:
    container_name: weddingapp_server
    build: ./weddingApp-Be
    depends_on:
      - mysql
    environment:
      MYSQL_HOST_IP: mysql
    ports:
      - 4000:4000
    links:
      - mysql
    command: npm run dev
  client:
    container_name: weddingapp_client
    build: ./weddingApp-Fe
    ports:
      - 3001:3000
    environment:
      - CHOKIDAR_USEPOLLING=true
    tty: true
volumes:
  db_data:

After the build was finished and I spinned it up I saw that my new data wasn't showing up, I still had the old data cached somewhere?

I checked the logs for my mysql image and got this:

2020-10-18 20:46:59+00:00 [Note] [Entrypoint]: Entrypoint script for

MySQL Server 8.0.21-1debian10 started. 2020-10-18 20:46:59+00:00

[Note] [Entrypoint]: Switching to dedicated user 'mysql' 2020-10-18

20:46:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server

8.0.21-1debian10 started. 2020-10-18T20:46:59.686360Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1 2020-10-18T20:46:59.693458Z 1 [System] [MY-013576] [InnoDB]

InnoDB initialization has started. 2020-10-18T20:46:59.987115Z 1

[System] [MY-013577] [InnoDB] InnoDB initialization has ended.

2020-10-18T20:47:00.115947Z 0 [System] [MY-011323] [Server] X Plugin

ready for connections. Bind-address: '::' port: 33060, socket:

/var/run/mysqld/mysqlx.sock 2020-10-18T20:47:00.196070Z 0 [Warning]

[MY-010068] [Server] CA certificate ca.pem is self signed.

2020-10-18T20:47:00.196193Z 0 [System] [MY-013602] [Server] Channel

mysql_main configured to support TLS. Encrypted connections are now

supported for this channel. 2020-10-18T20:47:00.200913Z 0 [Warning]

[MY-011810] [Server] Insecure configuration for --pid-file: Location

'/var/run/mysqld' in the path is accessible to all OS users. Consider

choosing a different directory. 2020-10-18T20:47:00.219538Z 0 [System]

[MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version:

'8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL

Community Server - GPL.

I am fairly new to docker and honestly I don't know what I am doing wrong. Any ideas?

1

1 Answers

2
votes

initdb scripts are only executed when your data directory (/var/lib/mysql) is empty.

Your data are not cached, but persisted to your host using your volume. So if this is a development work, you can simply delete the contents of db_data volume (or deleting and creating it again):

docker volume rm db_data
docker volume create db_data