The problem:
I’m trying to set up a Docker WordPress development environment on Windows 11 with wsl2. I created a docker-compose.yml and everything works apart from the node install. The container tries to start it and then just stops. Is something in my docker-compose file wrong?
I want to use node because I use gulp, npm and browser sync for my WordPress themes.
This is my docker-compose.yml:
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:
2
Answers
You have to use a Dockerfile otherwise it will never ever work!
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 .
Solution
command:npm start
in your node image and this should help you probablyForgive me if I have suggested something wrong because I am also learner in docker 🙂