How To Write A Dockerfile

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Chandrakant Suryawanshi

4/4/24
docker-file

Dockerfile for java application.


Dockerfile
1. First you need to select a base depending on the language used to build an application
FROM openjdk:14 (You can add base image from docker-hub and add the particular version
of software you want)
2. Create a working directory to compile and run java apps
WORKDIR /app (Here ‘/app’ is your working directory where you can compile and run java
apps)
3.Copy the code from the to docker container
COPY hello.java . (Here Hello.java is your source file and “ . “ is your container or
destination).
4.Compile the code
RUN javac hello.java (javac is used to compile the java code)
(Step 1-4 these are building stages of the container)
5.Run the java app
“CMD [“java”,“hello”] ( This is after build stage where you can give the commands to the
container by passing the arguments. This specifies the command to run when the
container starts. In this case, it runs the Java application using the hello.java file.)

Note: you can add the dependencies of your application in build stage.

Dockerfile for Node.js application


Chandrakant Suryawanshi
4/4/24
docker-file

Dockerfile

1.Use an official Node.js runtime as a base image

FROM node:14

2.Set the working directory in the container

WORKDIR /app (This sets the working directory inside the Docker container where
subsequent commands will be executed.)

3. COPY package*.json ./ (This copies the package.json and from your local
directory into the working directory in the container.)

4. RUN npm install (This runs the npm install command inside the container to
install the application dependencies specified in package.json.)

5. COPY . . (This copies the rest of the application code from your local directory into
the working directory in the container.)

6. EXPOSE 3000 (This instruction informs Docker that the container listens on port
3000 at runtime.)

7. CMD [“node”,”app.js”] (This specifies the command to run when the container
starts. In this case, it runs the Node.js application using the app.js file.)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy