I was following a tutorial serving content for a simple app using gulp, and managed to get it working on my local (Mac) machine, which allowed me to access the site from localhost:8000 in my browser. However, when I tried to dockerize it with the following Dockerfile
FROM node:14.17.2-stretch-slim
WORKDIR /app
COPY . .
RUN npm i npm@latest -g && npm install -g gulp
RUN npm install
RUN npm rebuild node-sass
CMD ["gulp", "serve", "--dir=folder"]
EXPOSE 8000
After building the docker image and running it with:
docker run -p 8000:8000 test-image
It looked like it was successfully started with the same console output I get when I was running it locally:
[08:55:46] Using gulpfile /app/gulpfile.js
[08:55:46] Starting 'serve'...
[08:55:46] Starting 'build'...
...
[08:55:53] Finished 'build' after 6.99 s
[08:55:53] Starting 'watch'...
[08:55:53] Starting '<anonymous>'...
[08:55:53] Starting 'watch:css'...
[08:55:53] Starting 'watch:html'...
[08:55:53] Starting 'watch:images'...
[08:55:53] Starting 'watch:js'...
[08:55:53] Webserver started at http://localhost:8000
[08:55:54] Finished '<anonymous>' after 52 ms
Also verified that there were no errors with running docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4c92aaf3a8a test-image "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp practical_borg
But when I tried to access localhost:8000 from my browser, I ran into localhost didn’t send any data. ERR_EMPTY_RESPONSE
I also tried docker run -p 127.0.0.1:8000:8000 test-image with the same result - not sure if I'm doing something wrongly, my understanding is that with docker on Mac, I should be able to access it from my localhost:8000 as long as the port is mapped correctly..