React App on Docker Project

3 / 6

Create Docker image using docker file

Docker file is a text file with the instructions to create a docker image file. Each instruction creates a layer in the image. Usually, the name of the docker file is kept as "Dockerfile". But we can also put the customised name. First, we will create the docker image of app for the development environment.

INSTRUCTIONS

To check all the files and directories into the react-app folder

ls

Dockerfile is already there into the repository. You just need to open the file using vi.

vi Dockerfile_dev

Make sure that all the commands mentioned below are written there.

Use an existing docker image as base

FROM node:alpine

Specify WORKDIR

WORKDIR /react-project

Copy the package.json from your work directory to the container's work directory. Until we copy the package.json file to the container work directory, npm install will not work.

COPY ./package.json .

Install dependencies

RUN npm install

Copy the source code from your work directory to the container's work directory.

COPY ./ ./

Startup Command

CMD ["npm", "run", "start"]

Save the file after checking all the mentioned commands. Then we will create the docker image using this dockerfile.

docker build -f Dockerfile_dev -t react-project .

Note - “-f” is used to specify the path of custom docker file and "-t" is used for tagging dockerfile.


No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...