0

I'm using teh following version of docker ...

localhost:client davea$ docker -v
Docker version 19.03.5, build 633a0ea

I have the following Dockerfile

FROM node:10-alpine AS alpine

WORKDIR /app

# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json /app/

## install only the packages defined in the package-lock.json (faster than the normal npm install)
RUN npm install

# Copy the contents of the project to the image
COPY . .

# Run 'npm start' when the container starts.
CMD ["npm", "run", "start"]

I then build and run the image like so ...

localhost:client davea$ docker build --tag client:1.0 .
Sending build context to Docker daemon  2.317MB
Step 1/6 : FROM node:10-alpine AS alpine
 ---> 34a10d47f150
Step 2/6 : WORKDIR /app
 ---> Using cache
 ---> c039266280ac
Step 3/6 : COPY package*.json /app/
 ---> Using cache
 ---> 69938dc0b9db
Step 4/6 : RUN npm install
 ---> Using cache
 ---> 6030b0efcbaf
Step 5/6 : COPY . .
 ---> Using cache
 ---> 0e804956b8f1
Step 6/6 : CMD ["npm", "run", "start"]
 ---> Using cache
 ---> 4367bce40216
Successfully built 4367bce40216
Successfully tagged client:1.0

localhost:client davea$ docker run --publish 3001:3000 --detach --name client client:1.0
97aa49d63d4014f62728187c56037d77b9de0fcf84bcca3114b585edb0650a95

However, when I then try and access my application, I get a connection refused, despite my attempt to connect on the port I specified ...

localhost:client davea$ wget http://localhost:3001
--2020-03-31 20:44:20--  http://localhost:3001/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:3001... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:3001... failed: Connection refused.

How else I can figure out what's going wrong here? I don't see any obvious flaws in my Docker file construction.

Edit: Here is the output from running "docker logs" on the stopped container ...

> client@0.1.0 start /usr/src/app
> react-scripts start

[HPM] Missing "target" option. Example: {target: "http://www.example.org"}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the client@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-04-01T02_04_40_090Z-debug.log
Dave
  • 15,639
  • 133
  • 442
  • 830
  • What port is your application listening on? Looks like you're not connecting the correct port in the container. – Alexander Leonov Apr 01 '20 at 02:12
  • I included "3001:3000" in my "docker run" command so I assumed I had exposed port 3001, which is what I tried to connect on via wget. – Dave Apr 01 '20 at 02:20

1 Answers1

0

You must expose the ports in dockerfile like;

...

EXPOSE 3000

CMD ["npm", "run", "start"]
serhattsnmz
  • 167
  • 1
  • 11
  • Thanks although after I checked "docker logs," (included as an edit to my question), there is anotehr error, which I don't understand -- "[HPM] Missing "target" option. Example: {target: "http://www.example.org"}". – Dave Apr 01 '20 at 02:24
  • @Dave - that looks like a separate problem with the application itself. – Alexander Leonov Apr 01 '20 at 02:26
  • I don't think it's docker problem. I think you must check your codes or share them to get more help – serhattsnmz Apr 01 '20 at 02:30