skip to Main Content

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


  1. You have to use a Dockerfile otherwise it will never ever work!

    Login or Signup to reply.
  2. 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

    1. Long way – You can use up a dockerfile, as mentioned by Tom , dockerfile is generally used to containerise your application so whatever code you need do just write it , then build your code into a docker image with node using Dockerfile , but in that case trouble is that everytime you are doing any code change you have reiterate over the same process and again build your code.
    2. Another simple way I could think of is add a command:npm start in your node image and this should help you probably

    Forgive me if I have suggested something wrong because I am also learner in docker 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search