Some days ago I confronted to docker, and more precisely with Springboot application. I had to create an image of my springboot app and export it in docker. So I decide to write an article to show you how I dockerize my app.
A little word about Docker
Docker bring the possibility to work easily with container in a simple way.
For the official docker website, docker is
Docker simplifies and accelerates your workflow, while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project.
And we can also find this explanation
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code. — OpenSource.com, what is Docker?
We can understand that Docker is a super power machine to help developer in their flow whitout thinking about infrastructure stuff. You code then dockerize !
Using Docker can help to solve troubles like “it works on your machine but not mine ?!” we hear a lot time a developer that complains on problem to run an application on his computer. It can prevents the confusion when a dev’s been working on their local machine on a project for days (or weeks), and as soon as it’s deployed it and the app won’t run. Most likely because somebody add dependencies that are necessary to run the application but missing in the pom.xml.
It’s what builds and executes Docker images from either a single Dockerfile or docker-compose.yml
creates a swarm of Docker Engines where you can deploy application services. You don’t need additional orchestration software to create or manage a swarm
This is what you use when you have an application made up of multiple microservices, databases and other dependencies. The docker-compose.yml allows you to configure all those services in one place and start them all with a single command.
Docker Machine is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts
A Docker image contains a set of instructions for creating a container that can run on the Docker platform.
Containers are instances of Docker images that can be run using the Docker run command. The basic purpose of Docker is to run containers.
The registry works basically like a git repository, allowing you to push and pull container images.
In order to be able to save (persist) data and also to share data between containers, Docker came up with the concept of volumes
Docker knows nothing ! you should tell to docker what you need in your container because there is nothing installed in it.
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.- Docker, Dockerfile Reference
a docker file begin with a base image, you will tel to your container what you want to install.
Then you will settup instruction that docker should follow (environment variable, where files lives …)
When creating this docker file you will certainly use some command that are common, here is some of them :
FROM: define the base image of the container
RUN: execute a command in a new layer on the top of image.
EXPOSE: informs Docker that the container listens on the specified network ports at runtime
ENV: sets the environment variable in a key – value form
VOLUME : creates a mount point with the specified name and marks it as holding externally mounted volumes from the native host or other containers.
Exemple of Java docker file