In order to create a dockerFile Name: mysql-docker-compose.yml
version: '3.8' services: uat_mysql_db: image: mysql:latest restart: always volumes: - "./.mysql-data/db:/Users/code2care/docker-volumes" ports: - 3306:3306 environment: MYSQL_ROOT_PASSWORD: root123 MYSQL_DATABASE: my_uat MYSQL_USER: mysqluser MYSQL_PASSWORD: mysqluser123
Docker MySQL Compose file details:
- version: It is the version of the docker-compose file, this should be based on your docker engine - know more: Compatibility matrix
- services: To define the list of services, we just have one here with name ie. uat_mysql_db,
- image: The name of the MySQL docker image with the tag as the latest, you can choose a tag with a specific version of MySQL e.g. 5.7 etc: https://hub.docker.com/_/mysql/tags
- restart: We always want to restart the container if it fails for some reason.
- volumes: We want to store the MySQL files on the local device at the specified location.
- ports: Exposing the local MySQL 3306 port to host device 3306 port.
- environment: Defined the MySQL root user password and optional superuser and password.
Running the MySQL Docker Compose file
Make sure you run the command from the directory where you have the .yml file.
% docker compose -f mysql-docker-compose.yml up
Logging into the MySQL prompt using root user
# docker exec -it my-docker-scripts-uat_mysql_db-1 /bin/sh sh-4.4# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.30 MySQL Community Server - GPL .. .. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | my_uat | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.02 sec)
Have Questions? Post them here!
- How to docker remove a container when it exits
- Install Python on Alpine Linux - Docker
- How to Rename Docker Image with none TAG and REPOSITORY?
- Remove all stopped containers in Docker using prune command
- [Fix] Docker Error response from daemon: manifest for :latest not found: manifest unknown
- [fix] Error response from daemon: conflict unable to remove repository reference ubuntu container is using its referenced image
- [Docker] Install Python3 on Alpine Linux
- Unable to find image docker latest locally
- How to Stop/Cancel/kill docker image pull
- How to know the Docker Engine Version
- [fix] Docker: OCI runtime exec failed unable to start container process
- [Solution] Alpine Docker apt-get: not found
- Install and Run Cassandra on Docker Desktop
- Install node on Alpine Linux Docker
- How to Copy files from Docker Container to Host System
- Install the minimal Linux on Docker (only 5 mb Alpine Linux)
- How to stop and start a docker container
- Docker - Error response from daemon: You cannot remove a running container
- Open Docker Desktop from macOS Terminal
- How to check installed docker version command
- How to know the Docker Sandbox ID of a Container Network?
- [fix] docker: Error response from daemon: dial unix docker.raw.sock: connect: no such file or directory.
- [Docker] Install Git on Alpine Linux
- Docker MySQL Compose File with Volume Example
- [fix] Docker: Alpine Linux - /bin/sh: bash: not found
- SharePoint Designer Workflow error - Coercion Failed: Input cannot be null for this coercion - SharePoint
- How to refresh Safari on Mac (macOS) using keyboard shortcut - MacOS
- Common Microsoft Teams sign in errors and how to fix - Teams
- Fix Something went wrong 0xCAA20004 [Microsoft Teams] - Teams
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0 - Java
- How to check if a port is in use using terminal [Linux or macOS] - MacOS
- Java JDBC Example with Oracle Database Driver Connection - Java
- Spring Boot Web + Thymeleaf Hello World Example in IntelliJ in 5 Easy Steps - Java