docker mysql service has to use port 3306 to start multiple :
version: '3.8'services: mysql_db1: image: mysql:8 environment: MYSQL_ROOT_PASSWORD: password1 MYSQL_DATABASE: db1 ports: - "3306:3306" # Maps host port 3306 to container port 3306 volumes: - db_data1:/var/lib/mysql mysql_db2: image: mysql:8 environment: MYSQL_ROOT_PASSWORD: password2 MYSQL_DATABASE: db2 ports: - "3307:3306" # Maps host port 3307 to container port 3306 volumes: - db_data2:/var/lib/mysqlvolumes: db_data1: db_data2:
-----------------------------------------------------------------------------------------
To add an
init.sql script to your MySQL Docker Compose setup to create the gitea and keycloak databases, follow these steps: Create the init.sql file.Create a file named
init.sql (or any other name ending in .sql, .sh, or .sql.gz) in a directory accessible to your docker-compose.yml file. For example, create a subdirectory named mysql-init and place init.sql inside it.Modify your docker-compose.yml.
In your
docker-compose.yml file, add a volumes entry to your MySQL service to mount your mysql-init directory into the /docker-entrypoint-initdb.d directory within the MySQL container.Run Docker Compose.
Navigate to the directory containing your
docker-compose.yml file and run:The
init.sql script will execute automatically when the MySQL container starts for the first time (when the /var/lib/mysql data directory is empty), creating the gitea and keycloak databases. Subsequent restarts will not re-run the init.sql script unless the mysql_data volume is cleared.
No comments:
Post a Comment