In order to create a docker
File Name: mysql-docker-compose.ymlversion: '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)
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to Docker,
- Install Docker on Mac using brew cask
- How to know the Docker Sandbox ID of a Container Network?
- How to Rename Docker Image with none TAG and REPOSITORY?
- How to know list of images available on your device
- Docker Alpine Linux and Apache2 Example
- Install Bash on Alpine Linux - Docker
- Docker Run Command Examples - Part 1
- Install the minimal Linux on Docker (only 5 mb Alpine Linux)
- [fix] docker: Error response from daemon: dial unix docker.raw.sock: connect: no such file or directory.
- Install RabbitMQ on Docker
- How to know docker Engine details
- [Fix] Docker Error response from daemon: manifest for :latest not found: manifest unknown
- How to stop and start a docker container
- How to create volume in Docker using Command
- How to know the Docker Engine Version
- [docker] Error response from daemon: No such container
- Install Docker for Mac using Home-brew Cask
- Docker - Incompatible CPU detected - M1/M2 Mac (macOS Sonoma)
- [fix] Docker Desktop App not starting on Mac (macOS)
- Unable to find image docker latest locally
- How to Stop/Cancel/kill docker image pull
- List of what's new in Docker 4.23
- [Docker M1/M2 Mac] qemu-x86_64: Could not open /lib64/ld-linux-x86-64.so.2: No such file or directory AWS CLI
- Install Docker Desktop on M1/M2 Apple Silicon ARM Chip Mac
- Docker - Running in Resource Saver mode
More Posts:
- Ways Compare Dates in Java Programming with Examples - Java
- [Fix] Microsoft AADSTS900561: The endpoint only accepts POST requests. Received a GET request. - Microsoft
- Check help on commands while being on sftp> prompt - FTP
- How to enable Wifi Calling on iPhone - iOS
- Java Interview Questions - Set 2: Core Principles - Java
- How to Generate SHA-512 digest in Notepad++ - NotepadPlusPlus
- How to write hello world different languages syntax - HowTos
- Permanently Set or Change $JAVA_HOME on Mac (macOS) - MacOS