docker-compose express mysql-server
最近一段时间在学习docker-compose应用到实际项目中,端午节放假利用了其中一天的时间,从0开始,到能够将express app 和mysql-server 两个container运行起来,并且顺利连接数据库,遇到了很多的问题,都一一解决了。
docker-compost.yml
version: '3'
services:
db:
image: mysql/mysql-server:5.7.22
ports:
- 3306:3306 // do not change to other port
volumes:
- ./schema:/docker-entrypoint-initdb.d // init database at first start mysql container, if init failed, please remove /data/db directory
- ./data/db:/var/lib/mysql
environment:
MYSQL_ROOT_HOST: "%"
MYSQL_HOST: "localhost"
MYSQL_ROOT_PASSWORD: "123456"
MYSQL_DATABASE: "Pomelo"
MYSQL_USER: "pomelo" // do not use root
MYSQL_PASSWORD: "123456"
MYSQL_LOG_CONSOLE: "true"
restart: always
app:
build: .
command: npm start
links:
- db
ports:
- 3000:3000
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules // if not set, npm install will not work!
start
docker-compose up --build
2 回复
后面的目标是打算将网易官方的lordofpomelo用docker-compose放到一块去。
试试docker stack