I have a web server (JS) I want to run into container, it runs but I cannot connect to it from host. I am a docker noob so I took a basic script and Dockerfile that worked for a similar case with go server
here is the script
#!/usr/bin/env bash
docker image build --file Dockerfile --tag guess-image .
docker container run --detach --publish 3000:3000 --rm --name guess-container guess-image
here is the Dockerfile
FROM alpine
# download the file with server
RUN wget address/where/to/download/zipped-JS.server
# extract
RUN apk add unzip
RUN unzip server.zip
WORKDIR ./server/
#unrelated stuff
...
# install javascript and install the server
RUN apk add npm
RUN npm install
# exposing port 3000
EXPOSE 3000
# run server
RUN node server.js
here is the docker ps result
:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5c8028cb79c3 3723e0b6e109 "/bin/sh -c 'node se…" 57 seconds ago Up 57 seconds 3000/tcp quirky_buck
when not dockerized, the JS server worked perfectly when browsing to http://localhost:3000/ I chose not to paste JS server but I can do it if you think it is relevant.
so any comment on those script is welcome (for example : my guts tells my it is far from being as lean as possible and also naming is far from what I would expect ... )
edit as pointed by David changing the last line by
# run server
CMD ["node" ,"server.js"]
made it work
edit this is not a web server just a simple local server that run in a browser and offer UI to test a script against another. Sorry for the awful wording.