服务器安装node
先安装nvm,然后安装node,npm
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
nvm install stable
node -v
npm i cnpm -g
npm i nrm -g
接着下载express框架
npm install express-generator -g
express app
编写docker-compose.yml
version: "3"
services:
node:
image: node:latest
container_name: node
hostname: node
ports:
- "3000:3000"
working_dir: /app
volumes:
- ./app:/app #创建项目根目录
links:
- redis
command: ["/bin/sh", "-c", "npm install && npm start"]
restart: always
redis:
image: redis:5-alpine
container_name: redis
hostname: redis
command: redis-server /usr/local/etc/redis/redis.conf --requirepass redis123
volumes:
- ./database:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
ports:
- "6379:6379"
restart: always
说明:docker-compose.yml是启动容器、配置端口和映射以及执行容器内虚拟机命令的命令集,常用的配置就那几个:image镜像、working_dir工作路径、command执行命令、volumes文件映射、ports端口映射、restart重启方式
效果
执行命令
docker-compose up -d
image.png
网友评论