[英]Node.js is not running in Docker is my docker-compose.yml correct?
I'm trying to set up a Docker WordPress development environment on Windows 11 with wsl2.我正在尝试使用 wsl2 在 Windows 11 上设置 Docker WordPress 开发环境。 I created a docker-compose.yml and everything works apart from the node install.我创建了一个 docker-compose.yml,除了节点安装外,一切正常。 The container tries to start it and then just stops.容器尝试启动它,然后停止。 Is something in my docker-compose file wrong?我的 docker-compose 文件有问题吗?
I want to use node because I use gulp, npm and browser sync for my WordPress themes.我想使用节点,因为我为我的 WordPress 主题使用 gulp、npm 和浏览器同步。
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- dbdata:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wp-content:/var/www/html/wp-content
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
node:
restart: "no"
image: node:latest
container_name: nodejs
depends_on:
- wordpress
volumes:
- node-data:/usr/src/app
ports:
- 3000:3000
- 3001:3001
volumes:
dbdata:
wp-content:
node-data:
You have to use a Dockerfile otherwise it will never ever work!您必须使用 Dockerfile 否则它将永远无法工作!
Problem is that you have mentioned to spin up the docker container but just think for a sec how will you command node to tell that what it needs to do.When it sees no action commanded it basically closes up.问题是您已经提到要启动 docker 容器,但请想一想您将如何命令节点来告诉它需要做什么。当它没有看到任何命令时,它基本上会关闭。
Solution解决方案
command:npm start
in your node image and this should help you probably我能想到的另一种简单方法是在您的节点映像中添加一个command:npm start
,这可能会对您有所帮助Forgive me if I have suggested something wrong because I am also learner in docker:)如果我提出了错误的建议,请原谅我,因为我也是 docker 的学习者:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.