0

So I'm trying to run a Mysql docker container with some tables setup. It looks like when I do it on the terminal with the following commands, I'm able to access a mysql terminal and access created tables. The Dockerfile, with initial.sql, the file that creates the tables, in the same folder:

FROM mysql:5.7.30

ENV MYSQL_DATABASE football_simulation
ENV MYSQL_ROOT_PASSWORD password
ENV MYSQL_USER alee
ENV MYSQL_PASSWORD anotherpassword
ADD initial.sql /docker-entrypoint-initdb.d

EXPOSE 3306

Docker commands:

docker build -t test/SNAPSHOT .
docker run --name footysimdb -p3308:3306 -d test/SNAPSHOT
docker exec -it footysimdb /bin/bash

Login to mysql terminal and access tables:

mysql -ualee -panotherpassword
use football_simulation;
show tables;

This is fine. I'm trying to simplify this by using docker-compose.yml now. However, running docker-compose up on this docker-compose.yml in the same directory does not work:

version: '3'

services:

        mysql-development:
                image: mysql:5.7.30
                environment:
                        MYSQL_ROOT_PASSWORD: password
                        MYSQL_DATABASE: football_simulation
                        MYSQL_USER: alee
                        MYSQL_PASSWORD: anotherpassword
                ports:
                - "3308:3306"
                volumes:
                        - initial.sql  /docker-entrypoint-initdb.d/

        admin:
                image: adminer
                ports:
                - "8080:8080"

The database football_simulation is accessible on port 8080 but the tables do not show up. What am I doing wrong?

1
  • 1
    try changing volumes to ./initial.sql:/docker-entrypoint-initdb.d/initial.sql and make sure that your file is in the compose context. Commented Jun 11, 2020 at 8:22

1 Answer 1

1

You are doing the mounting incorrect. First you do not use : delimeter. Also the way you are trying to do it looks like initial.sql will be interpreted as named volume. If you want to mount single file to a directory docker-entrypoint-initdb.d in the container - you should use bind mounts. It would look like :

./initial.sql:/docker-entrypoint-initdb.d/

so initial.sql file from the current context will be mounted through bind mount into /docker-entrypoint-initdb.d directory as initial.sql file.

You can read about different types of volumes in offical docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.