Table of Contents
Issue
I have a docker.compose file and when I start it I want it to create a database with some tables.
My docker compose:
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: todo
MYSQL_ROOT_PASSWORD: password!
MYSQL_PASSWORD: password!
volumes:
- ./DbScripts/DumpTodoOnly.sql:/docker-entrypoint-initdb.d/DumpTodoOnly.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: server
build:
context: ./BE
dockerfile: ./Dockerfile.prod
depends_on:
- mysql
environment:
MYSQL_HOST_IP: mysql
ports:
- 4000:4000
links:
- mysql
client:
container_name: FE
build:
context: ./FE
dockerfile: ./Dockerfile.prod
ports:
- 3000:3000
environment:
- CHOKIDAR_USEPOLLING=true
tty: true
volumes:
db_data:
project structure:
the actual sql file:
— MySQL dump 10.13 Distrib 8.0.18, for Win64 (x86_64)
— Host: localhost Database: todo
— Server version 8.0.18
/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT /;
/!40101 SET @[email protected]@CHARACTER_SET_RESULTS /;
/!40101 SET @[email protected]@COLLATION_CONNECTION /;
/!50503 SET NAMES utf8 /;
/!40103 SET @[email protected]@TIME_ZONE /;
/!40103 SET TIME_ZONE=’+00:00′ /;
/!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 /;
/!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 /;
/!40101 SET @[email protected]@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’ /;
/!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 */;
—
— Table structure for table todos
DROP TABLE IF EXISTS `todos`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `todos` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`todotext` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
—
— Table structure for table users
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `users` (
`Id` varchar(36) NOT NULL,
`Email` varchar(200) NOT NULL,
`Password` binary(60) NOT NULL,
`ChangedPassword` bit(1) NOT NULL,
`FirstName` varchar(45) NOT NULL,
`LastName` varchar(45) NOT NULL,
`ImageId` varchar(36) DEFAULT NULL,
`SeqRef` varchar(36) DEFAULT NULL,
PRIMARY KEY (`Id`),
UNIQUE KEY `Email_UNIQUE` (`Email`),
UNIQUE KEY `Id_UNIQUE` (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci KEY_BLOCK_SIZE=2;
/*!40101 SET character_set_client = @saved_cs_client */;
—
— Dumping routines for database ‘todo’
/*!40103 SET [email protected]_TIME_ZONE */;
/*!40101 SET [email protected]_SQL_MODE /;
/!40014 SET [email protected]_FOREIGN_KEY_CHECKS /;
/!40014 SET [email protected]_UNIQUE_CHECKS /;
/!40101 SET [email protected]_CHARACTER_SET_CLIENT /;
/!40101 SET [email protected]_CHARACTER_SET_RESULTS /;
/!40101 SET [email protected]_COLLATION_CONNECTION /;
/!40111 SET [email protected]_SQL_NOTES */;
— Dump completed on 2022-03-16 20:20:30
When I run docker-compose up I see:
And in my php admin I dont see any users or todos table:
What have I missed?
Solution
Alright this is somewhat not great to find an answer when you post but for those with similar issue:
Apperently When you run the docker-compose up command the database configuration gets stored and survices a restart. To make this I had to:
docker-compose down -v
Answer found here
Note @Sebastiaan Renkens answer
Answered By – CodingLittle
Answer Checked By – Pedro (BugsFixing Volunteer)