-1

I'm trying to develop astro.js inside docker.

Here's my docker-compose.yml file:

version: "3.9"
services: 
    site:
        image: node:lts-bullseye-slim
        ports:
            - 3000:3000
        volumes:
            - /project:/project
        command: >
            sh -c
            "
            cd /project
            && npm run install
            && npm run dev &
            tail -f /dev/null
            "

And I can see that astro is running inside the docker. I can curl localhost:3000 from inside the docker container and it shows me the default page of the astro project.

However, when I try to reach localhost:3000 on my laptop, it gives ms ERR_EMPTY_RESPONSE error.

What should I do?

Update:
/project is just a very simple typical astro application created with npx create-astro command.

Big boy
  • 1,113
  • 2
  • 8
  • 23

1 Answers1

3

I try to use your docker-compose.yml file then I found some issue as follow.

  1. The first time I use "docker-compose up" command and "docker logs my-astro-site_site_1". The logs show "npm run install is not found". so I change content of "docker-compose.yml" from "&& npm run install" to "&& npm install" Container logs
  2. After that when I run "docker-compose up" and log the container. It says "You installed esbuild on another platform than the one you're currently using." because I use M1 and install dependency outside container before start docker compose. so I delete node_modules and package-lock.json and run "docker-compose up" Container logs
  3. Finally I found the same issue that you found "ERR_EMPTY_RESPONSE". It's because you don't expose port when your start with dev. so I change content of "docker-compose.yml" a bit from "&& npm run dev &" to "&& npm run dev -- --host 0.0.0.0 &" and run "docker-compose up". It's work!. My docker compose file look like this:

version: "3.9"
services: 
    site:
        image: node:lts-bullseye-slim
        ports:
            - 3000:3000
        volumes:
            - /Users/komphet/dev/my-astro-site:/project
        command: >
            sh -c
            "
            cd /project
            && npm install
            && npm run dev -- --host 0.0.0.0 &
            tail -f /dev/null
            "

I hope it will be helpful to your software development. Enjoy!

  • Such a comprehensive response. Thank you so much. Yes that was my problem that I had to bind to all IP addresses. – Big boy Sep 05 '22 at 03:05