当前位置:网站首页>Docker compose配置MySQL并实现远程连接
Docker compose配置MySQL并实现远程连接
2022-07-06 01:15:00 【php的绯闻女友】
您需要确保您的运行环境达到了以下的要求:
- Docker Engine
- Docker CLI
- Docker Compose
docker-compose.yml
version: '3.7'
services:
mysql:
image: "mysql/mysql-server:8.0"
environment:
TZ: "Asia/Shanghai"
MYSQL_ROOT_PASSWORD: "123456" # 设置root密码
MYSQL_DATABASE: "library_manager" # 设置数据库
MYSQL_USER: "library_manager" # 下面的项目连接Mysql的时候,使用这个用户名
MYSQL_PASSWORD: "123456"
ports:
- "33065:3306" # 映射,如果需要远程连接Docker中的数据库,这一步很重要
volumes:
- mysql-data:/var/lib/mysql
- ./.github/init.sql:/docker-entrypoint-initdb.d/init.sql
restart: "always"
container_name: "mysql"
远程连接效果如下:
docker内的项目连接数据库时的配置
environment:
APP_ENV: "${APP_ENV:-prod}"
DB_HOST: "mysql"
DB_PORT: "3306" # 因为在同一个环境,所以直接用3306端口就行
DB_USERNAME: "library_manager"
DB_PASSWORD: "password"
DB_DATABASE: "database
边栏推荐
- Installation and use of esxi
- The value of applet containers
- MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
- False breakthroughs in the trend of London Silver
- Condition and AQS principle
- Recursive method to realize the insertion operation in binary search tree
- Four commonly used techniques for anti aliasing
- cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
- Is chaozhaojin safe? Will it lose its principal
- GNSS terminology
猜你喜欢
Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
File upload vulnerability test based on DVWA
False breakthroughs in the trend of London Silver
Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration
关于softmax函数的见解
Loop structure of program (for loop)
Kotlin basics 1
Test de vulnérabilité de téléchargement de fichiers basé sur dvwa
Fibonacci number
MobileNet系列(5):使用pytorch搭建MobileNetV3并基于迁移学习训练
随机推荐
基於DVWA的文件上傳漏洞測試
Starting from 1.5, build a micro Service Framework - call chain tracking traceid
Building core knowledge points
95后CV工程师晒出工资单,狠补了这个,真香...
WordPress collection plug-in automatically collects fake original free plug-ins
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
激动人心,2022开放原子全球开源峰会报名火热开启
037 PHP login, registration, message, personal Center Design
Recursive method converts ordered array into binary search tree
Unity | 实现面部驱动的两种方式
Mysql--- query the top 5 students
The value of applet containers
Cve-2017-11882 reappearance
[pat (basic level) practice] - [simple mathematics] 1062 simplest fraction
Exciting, 2022 open atom global open source summit registration is hot
Use of crawler manual 02 requests
Vulhub vulnerability recurrence 75_ XStream
ORA-00030
Condition and AQS principle