Abhishek Poddar
Abhishek Poddar

Reputation: 249

How do I make my Docker image of MERN stack application using ubuntu:20.04 as a base image of my container?

Greeting from my side.... I am very new to the docker. And I just learn the basics of docker like : containers , images, volumes, docker-compose. So I have one task that I need to dockerise my MERN stack app i.e. Mongodb, Express, React, Node. But the condition is that I used operating system as ubuntu:20.04 version. Now I need to dockerise my MERN app and the base image of my docker image file is ubuntu:20.04. How can I do that ? Like I am trying like this :

FROM node:16-ubuntu:20.04
WORKDIR /app/
COPY package*.json .
RUN npm install
COPY . .
CMD ["npm","run","dev"]

When I try to build it it gives me an error :

failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to parse stage name "node:16-ubuntu:20.04": invalid reference format
ERROR: Service 'app' failed to build : Build failed

Can anyone can solve my problem ? or guide me for the same. Thank you!

Upvotes: 0

Views: 289

Answers (1)

sidharth vijayakumar
sidharth vijayakumar

Reputation: 1571

The mistake you have done is you are trying to pull a non existing docker image.You need not mention Ubuntu:20.04 in your base image try to find a base image in node 16.x

I could find this image and it should be fine and compatible in linux machines. Try using this base image

From node:16.3.0-alpine

If you need some other base image go to docker hub and search for node and in filter search node:16 base images.

node docker images

To build a react image try to follow some blogs to get an idea what all steps you need to do in the docker file

Build a react image

How I have built a react image

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

Ensure that the port you expose and port you configure is the same. This could be found in web pack.config.js

  devServer: {
    inline: true,
    host: '0.0.0.0',
    port: 7777
  },

Upvotes: 1

Related Questions