2

I am trying to build a Docker image with given below steps and try to run a docker build command to generate an image in Windows 10 machine. I am not getting any error or so for the steps I am following. Can someone help me on below and also let me know if any details are required.

FROM node:10-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "npm","run","start" ]

Powershell Screenshot

Heet Shah
  • 105
  • 1
  • 3
  • 10
  • From which port you want to use your application? – onuriltan Jun 02 '20 at 14:55
  • please add this like in your dockerfile `EXPOSE 8080` – Dupinder Singh Jun 02 '20 at 15:12
  • That looks like a pretty routine Node Dockerfile. Can you edit the question to include the actual error you're getting, in the question itself (not behind the link and not as an image)? – David Maze Jun 02 '20 at 16:02
  • Hi, StackOverflow is not allowing to me upload an image due to some policy for a new contributor. But thank you guys for your all help and now I am not facing any issues. – Heet Shah Jun 03 '20 at 17:28

2 Answers2

2

In your dockerfile you are missing a port to expose which is important to communicate from container to outside of the world.

Add this line in your dockerfile

EXPOSE 8080

PS:

Your dockerfile should look like following. And place your dockerfile in the root directory of your project.

FROM node:10

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 8080

CMD [ "npm","run","start" ]
Dupinder Singh
  • 7,175
  • 6
  • 37
  • 61
  • Hi Dupinder, My issue has been resolve and I am exposing the port while running docker run -p 3000:3000 – Heet Shah Jun 03 '20 at 17:31
  • @HeetShah congratulations. Enjoy Happy Docker Happy Containers Happy to help – Dupinder Singh Jun 03 '20 at 18:10
  • can you please help me with this issue https://stackoverflow.com/questions/62179379/not-able-to-figure-out-why-docker-compose-up-is-not-running-my-react-js-app/62179639#62179639 – Heet Shah Jun 03 '20 at 18:26
  • @HeetShah I answered your other question too, please verify and if this current problem issue is resolved then please vote the answer – Dupinder Singh Jun 04 '20 at 07:20
0

Sometimes when we copy a docker command, it also copies the "$" sign. Try removing the sign and build the image again.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 02 '23 at 10:10