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?
./initial.sql:/docker-entrypoint-initdb.d/initial.sqland make sure that your file is in the compose context.