Since the layers are readonly whenever you modify any existing content, the file gets copied to read/layer and changes are recored in the R/W. This approach is called as copy-on-write
How to preserve the data changed by the docker container
Persistence/Preserving the data even after the container is deleted can be acheived by storing the data outside container. To do this we have 3 options
volumes
bind mounts
tmpfs
Bind mounts
are stored anywhere on the host system.
Oldest option available for persistenting the changes
In CI/CD we build applications and for building applications if we want to use docker containers then this multistage build concept will be handy
Let me give a simple example of a java application
git clone https://github.com/wakaleo/game-of-life
# java 8 installed and maven install
cd game-of-life
mvn package
In Traditional ways
Now after the Package is created, Ensure you have Dockerfile which creates the image
Create the image and push the image to docker registry
When you want to deploy application the pull from registry
Multistage build
Build the package as part of your docker image build
Create a Dockerfile as shown
FROM maven:3-openjdk-8 as builder
RUN git clone https://github.com/wakaleo/game-of-life.git
RUN cd game-of-life && mvn package
FROM tomcat:8
COPY --from=builder /game-of-life/gameoflife-web/target/gameoflife.war /usr/local/tomcat/webapps/gameoflife.war
EXPOSE 8080
Now as part of building docker image application code gets build and a package is generated which will be copied into destination container
docker image build -t spcms:1.0 .
Docker logging
docker logs command show the loggs by a running continer
This docker logs will show the logs from STDOUT, STDERR
In docker to configure logging, we have loggin driver plugins