当前位置:网站首页>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
边栏推荐
- golang mqtt/stomp/nats/amqp
- 电气数据|IEEE118(含风能太阳能)
- MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
- 直播系统代码,自定义软键盘样式:字母、数字、标点三种切换
- 037 PHP login, registration, message, personal Center Design
- A preliminary study of geojson
- Zhuhai's waste gas treatment scheme was exposed
- 2020.2.13
- 基于DVWA的文件上传漏洞测试
- How to see the K-line chart of gold price trend?
猜你喜欢
Cve-2017-11882 reappearance
伦敦银走势中的假突破
Fibonacci number
VMware Tools installation error: unable to automatically install vsock driver
VMware Tools安装报错:无法自动安装VSock驱动程序
Exciting, 2022 open atom global open source summit registration is hot
可恢复保险丝特性测试
Ubantu check cudnn and CUDA versions
IP storage and query in MySQL
Finding the nearest common ancestor of binary tree by recursion
随机推荐
What is the most suitable book for programmers to engage in open source?
面试必刷算法TOP101之回溯篇 TOP34
View class diagram in idea
Interview must brush algorithm top101 backtracking article top34
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
282. Stone consolidation (interval DP)
Recursive method to realize the insertion operation in binary search tree
Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition
The growth path of test / development programmers, the problem of thinking about the overall situation
VSphere implements virtual machine migration
[Arduino syntax - structure]
Who knows how to modify the data type accuracy of the columns in the database table of Damon
Recommended areas - ways to explore users' future interests
Four commonly used techniques for anti aliasing
Vulhub vulnerability recurrence 74_ Wordpress
ThreeDPoseTracker项目解析
The population logic of the request to read product data on the sap Spartacus home page
黄金价格走势k线图如何看?
Logstash clear sincedb_ Path upload records and retransmit log data
A preliminary study of geojson