Docker References in the blog
Docker container and Image
- Refer Here
- Refer Here
- Image Concept in Docker
docker image pull openjdk:8 vi Dockerfile FROM openjdk:8 LABEL author="khaja" LABEL version="0.2" LABEL project="QT" RUN wget https://referenceappkhaja.s3-us-west-2.amazonaws.com/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar EXPOSE 8080 ENTRYPOINT ["java"] CMD ["-jar", "spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar"] # build spring petclinic docker image build -t spc:0.1 .
- Now lets inspect images and focus of Layer
docker image inspect openjdk:8 docker image inspect spc:0.1
- Docker image is collection of docker layers
- When are layers created?. Mostly they are created when the content is changed (Executing RUN,COPY,ADD instruction). Lets experiment to create a new docker image spc:0.2
FROM openjdk:8 LABEL author="khaja" LABEL version="0.2" LABEL project="QT" RUN wget https://referenceappkhaja.s3-us-west-2.amazonaws.com/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar RUN mkdir /test EXPOSE 8080 ENTRYPOINT ["java"] CMD ["-jar", "spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar"]
- Now verify the image layers with openjdk:8 and you should see 2 layers.
- So creating too many layers is not optimal. Use RUn statement carefully
- The docker image layers are readonly
- Try to create 2 container with spc:0.2
docker container run -d -P spc:0.2 docker container run -d -P spc:0.2
- When we create a container, an extra R/w layer is created. All the changes done in that container will be stored in R/W layer. When we delete the container the R/W layer gets deleted. So in Docker to preserve changes done inside container we need to take extra measure (Volume)
Stateful and Stateless Application
- Stateful applications use local storage to preserve application data/config
- Stateless applications don’t use local storage, they rather store the state(application/data) in database/external system
- Docker is used in both stateful and stateless applications.
- Ensure extra caution in stateful applications.
pwdcommands in the following containers and observe the behavior
docker container run -it openjdk:8 /bin/bash docker container run -it jenkins /bin/bash docker container run -it tomcat:8 /bin/bash