Docker contd
Dockerfile
- Dockerfile has instructions to build a docker image
FROM
- This helps in selecting a base image
- Experiments
- Exploring options of FROM
- choosing different base images
Experiment 1
- Lets just add FROM statement in Dockerfile
FROM eclipse-temurin:17-jdk
- pull the base image
docker image pull eclipse-temurin:17-jdkand verify imagesdocker image ls
- Now lets build image
- Now lets add metadata
FROM eclipse-temurin:17-jdk
LABEL author="khaja"
- There is a base image called as scratch which is empty
- Platforms:
- amd
- arm
RUN
- Run instruction executes the command during image building
- Consider the following Dockerfile
FROM ubuntu:24.04
LABEL author="khaja"
LABEL project="classroom"
RUN apt update &&
apt install openjdk-17-jdk -y
ADD or COPY
- ADD can copy files from local as well as web into docker image
- COPY can copy the local files or folders into docker image
- Sample Dockerfile
FROM ubuntu:24.04
LABEL author="khaja"
LABEL project="classroom"
RUN apt update && \
apt install openjdk-17-jdk -y
ADD https://referenceappslt.s3.ap-south-1.amazonaws.com/spring-petclinic-3.3.0-SNAPSHOT.jar /spring-petclinic-3.3.0-SNAPSHOT.jar
ENTRYPOINT/CMD
- This is used to start the application
Note
- Remove all images
docker image rm -f $(docker image ls -q) - When we create a container, container searches for start up command (CMD) if not found searches in base image startup
- container is running as long as startup command is in running state
