Docker Desktop WSL
https://docs.docker.com/get-docker/
https://docs.docker.com/get-started/overview/
With Docker, you can manage your infrastructure in the same ways you manage your applications. shipping, testing, and deploying code quickly
Docker provides the ability to package and run an application in a loosely isolated environment called a container.
An image is a read-only template with instructions for creating a Docker container.
Container image : package (all code, tools)
Often, an image is based on another image, with some additional customization.
To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it.
makes images so lightweight, small, and fast, when compared to other virtualization technologies.
https://www.docker.com/resources/what-container/
Container: runtime - ex Docker Engine
Container >< vitual machine
A container is a runnable instance of an image.
A container is defined by its image as well as any configuration options you provide to it when you create or start it.
You can create, start, stop, move, or delete a container using the Docker API or CLI.
A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default.
Desktop
Pre (Optional): install docker plugin IDE
https://docs.docker.com/engine/reference/builder/
https://docs.docker.com/engine/reference/commandline/run/
Example:
FROM maven:3.6.3-jdk-11-openj9 AS build
USER root
WORKDIR /app
COPY . .
RUN mvn clean package
FROM adoptopenjdk/openjdk11
USER root
WORKDIR /app
COPY --from=build /app/target/simple-demo-0.0.1-SNAPSHOT.jar ./simple-demo.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "simple-demo.jar"]
.dockerignore file
If this file exists, the CLI modifies the context to exclude files and directories that match patterns in it. This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon and potentially adding them to images using ADD or COPY
Build an image from a Dockerfile
docker build . -t <image name>
docker run -p 8080:8080 <image name>
You also use the -p flag to create a mapping between the host’s port 3000 to the container’s port 3000. Without the port mapping, you wouldn’t be able to access the application.
jib-maven-plugin
What
Jib is an open-source Java tool maintained by Google for building Docker images of Java applications. It simplifies containerization since with it, we don't need to write a dockerfile.
How
Config in pom file
Build and push the image to a container registry
mvn compile jib:build
https://techmaster.vn/posts/36412/dockerize-spring-boot-app-bang-google-jib-phan-2
https://github.com/GoogleContainerTools/jib/blob/master/jib-maven-plugin/README.md
https://cloud.google.com/java/getting-started/jib