python on ubuntu
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y python3.9 python3-pip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
CMD ["python3.9"]
From: pull ubuntu image
Run : it execute python and dependenciesinside container
Cmd : it will execute starting of container during running time
Output
We can see we get python dependencies with ubuntu image
maven on ubuntu
FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y openjdk-11-jdk maven && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN java -version &&mvn -version
WORKDIR /app
COPY . /app
EXPOSE 8080
RUN ["mvn", "clean", "install"]
From: pull ubuntu image
Run: : it execute maven dependencies inside container
Workdir: to set app directory
Copy: ./app to copy files from local to container
Run: run maven clean and install
Expose: we give the port for it
Output:
DOCKER WITH GIT
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y git && \
apt-get clean
WORKDIR /workspace
CMD ["git", "—version”]
From: pull ubuntu image
Run: get the git dependencies
output
Python sample flask on ubuntu
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y python3.9 python3-pip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY . /app
CMD ["python","[Link]"]
From : pull ubuntu image
RUN : to execute python and dependencies inside container
Workdir: to set app directory
COPY . /app to copying files from local to container
RUN : pip install adding dependencies for python code
Entrypoint: it will execute while starting the container inside
CMD:it will execute while starting the container inside
output
Node-js dockerfile
FROM node:alpine
WORKDIR /app
COPY [Link] [Link] /app/
RUN npm install
COPY . /app/
EXPOSE 3000
CMD ["npm", "start"]
From: pull alphine image
Workdir: to set app directory
COPY . /app to copying files from local to container
Expose: it allows port 3000
Cmd : :it will execute while starting the container inside
Mavenubuntu and tomcat
FROM ubuntu:latest As builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y openjdk-11-jdk maven && \
apt-get clean && \ rm -rf /var/lib/apt/lists/*
RUN java -version &&mvn -version
WORKDIR /app
COPY . /app
EXPOSE 8080
RUN ["mvn", "clean", "install"]
FROM tomcat:latest
COPY --from=builder /app/webapp/target/[Link] /usr/local/tomcat/webapps/[Link]
RUN cp -R /usr/local/tomcat/[Link]/* /usr/local/tomcat/webapps
~
From: pull ubuntu image
Run: : it execute maven dependencies inside container
Workdir: to set app directory
Copy: ./app to copy files from local to container
Run: run maven and java dependencies
Expose: we give the port
From : we again pull tomcat image
Copy: copy the warfiles from local to container
Here we used asbuild do that we can run multi stage :docker maven and tomcat in one file
Output
Sample python application with docker file
FROM python:3.6
MAINTAINER veera "veera.narni232@[Link]"
COPY . /app
WORKDIR /app
RUN pip install -r [Link]
ENTRYPOINT ["python"]
CMD ["[Link]"]
From : pull python image
Copy: copy files from local to container
Run: it execute [Link] dependencies
Cmd : :it will execute while starting the container inside
outside
Maven docker file
FROM ubuntu:20.04
RUN apt-get update \
&& apt-get install -y maven \
&& apt-get clean
WORKDIR /app
COPY . /app
RUN mvn install
CMD ["mvn", "--version"]
From: pull ubuntu image
Run: : it execute maven dependencies inside container
Workdir: to set app directory
Copy: ./app to copy files from local to container
Run: run maven clean and install
sample application with centos on python
FROM centos:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN yum -y update; yum -y install python3 python3-pip; yum clean all;
WORKDIR /app
COPY . /app
RUN pip install -r [Link]
ENTRYPOINT ["python3"]
CMD ["[Link]"]
From: pull centos image
Run: to execute python and dependencies inside container
Copy: copy files from local to container
Run: pip dependencies will execute
Cmd: it will run the python code during run time
Output
maven on tomcat
FROM maven:3.8.4-eclipse-temurin-17 AS build
RUN mkdir /app
WORKDIR /app
COPY . .
RUN mvn package
FROM tomcat:latest
COPY --from=build
/app/webapp/target/[Link]/usr/local/tomcat/webapps/[Link]
RUN cp -R /usr/local/tomcat/[Link]/* /usr/local/tomcat/webapp
From: pull ubuntu image
Run: : it execute maven dependencies inside container
Workdir: to set app directory
Copy: ./app to copy files from local to container
Run: run maven and java dependencies
Expose: we give the port
From : we again pull tomcat image
Copy: copy the warfiles from local to container
Python image with centos base image
FROM centos/python-38-centos7
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r [Link]
EXPOSE 80
CMD ["python", "[Link]"]
From: pull centos image
Run: to execute python and dependencies inside container
Copy: copy files from local to container
Run: pip dependencies will execute
Cmd: it will run the python code during run time
output