当前位置:网站首页>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
边栏推荐
- Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
- VSphere implements virtual machine migration
- Recommended areas - ways to explore users' future interests
- Threedposetracker project resolution
- Logstash clear sincedb_ Path upload records and retransmit log data
- 朝招金安全吗 会不会亏损本金
- Finding the nearest common ancestor of binary search tree by recursion
- 面试必刷算法TOP101之回溯篇 TOP34
- KDD 2022 | EEG AI helps diagnose epilepsy
- Exciting, 2022 open atom global open source summit registration is hot
猜你喜欢
Hcip---ipv6 experiment
View class diagram in idea
cf:C. The Third Problem【关于排列这件事】
Starting from 1.5, build a micro Service Framework - call chain tracking traceid
WordPress collection plug-in automatically collects fake original free plug-ins
关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
282. Stone consolidation (interval DP)
Cve-2017-11882 reappearance
Fibonacci number
Differences between standard library functions and operators
随机推荐
037 PHP login, registration, message, personal Center Design
GNSS terminology
Promise
Tcpdump: monitor network traffic
Finding the nearest common ancestor of binary search tree by recursion
3D模型格式汇总
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
面试必刷算法TOP101之回溯篇 TOP34
MATLB|实时机会约束决策及其在电力系统中的应用
普通人下场全球贸易,新一轮结构性机会浮出水面
测试/开发程序员的成长路线,全局思考问题的问题......
Beginner redis
ORA-00030
FFT learning notes (I think it is detailed)
程序员搞开源,读什么书最合适?
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Differences between standard library functions and operators
Synchronized and reentrantlock
Questions about database: (5) query the barcode, location and reader number of each book in the inventory table
ADS-NPU芯片架构设计的五大挑战