


How to Initialize a MySQL Database with Schema Inside a Docker Container?
Dec 25, 2024 pm 12:34 PMInitializing MySQL Database with Schema in Docker Container
Initializing a MySQL database with schema within a Docker container can be challenging. Here's a solution to address this issue:
1. Dump MySQL Schema
Dump your MySQL schema to a file using the following command:
1 |
|
2. Add Schema File to Dockerfile
In your Dockerfile, add the schema file to the /docker-entrypoint-initdb.d directory using the ADD command. The docker-entrypoint.sh script in the container will execute any .sql files in this directory against the database.
Sample Dockerfile:
1 2 3 4 5 6 7 8 9 10 |
|
3. Build and Run Docker Container
Once the Dockerfile is modified, build and run the container:
1 2 |
|
4. Additional Notes
- Ensure that the MySQL user has sufficient privileges to create the database and tables.
- Adjust the MySQL host, user name, password, and schema name as needed.
- Verify that the docker-entrypoint.sh script is executable by the root user within the container, as it is responsible for executing the schema initialization.
By following these steps, you can successfully initialize a MySQL database with schema within a Docker container and eliminate the issue of the CMD not executing properly.
The above is the detailed content of How to Initialize a MySQL Database with Schema Inside a Docker Container?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Reduce the use of MySQL memory in Docker

How do you alter a table in MySQL using the ALTER TABLE statement?

How to solve the problem of mysql cannot open shared library

Run MySQl in Linux (with/without podman container with phpmyadmin)

What is SQLite? Comprehensive overview

Running multiple MySQL versions on MacOS: A step-by-step guide

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?

How do I configure SSL/TLS encryption for MySQL connections?
