Recently I finished the Docker for Java Developers course from Spring Guru on Udemy.
My goal was to learn and understand Docker so far, that I should be able to use it in my development and learning process.
- start a database for development and test purposes locally. Docker makes it possible to spare the installation process, and gives you a running database within seconds.
- start related applications and services as a bundle fast and easy. You do not need to take care of the application startup order any more, as Docker compose starts the components of your architecture.
- Check out a technology or a tool without needing to install and configure it. I already used Docker to learn Hazelcast, MongoDB, JIRA and Elastic Stack with help of Docker. And the possibilities are unlimited. You can find for nearly all service, tool or interesting new technology a starter kit on Docker Hub, and you can start playing within minutes.
Here are the lessons, I learned and experiences I made:
- At the time of writing this article, you need the pro version of Windows for installing Docker on a Windows host. Therefore I decided to install Docker on Ubuntu, running on VirtualBox.
Using Docker and the necessary development tools is a memory intensive game. I recommend to give at least 8 GB memory to your VirtualBox image. - Installing Docker on Ubuntu is very straightforward. You can find the necessary info at the Docker documentation site. After the installation, you should set the possibility to run Docker without the sudo command.
Therefore you need to creat a docker user group and add your user to it:
$ sudo groupadd docker
$ sudo usermod -aG docker $USER - It is very easy to convert your Spring Boot Application to Docker image. You need to define your Docker file, like:
FROM openjdk:11
EXPOSE 8080
ADD mySpringBootApp-1.0-SNAPSHOT.jar mySpringBootApp.jar
ENTRYPOINT [“java”, “-jar”, “mySpringBootApp.jar”]
and create the image with the following command:
sudo docker build -f DockerFile -t dockerdemo .To start the image, you need to run this command:
sudo docker run -p 8080:8080 dockerdemo - It is handy to learn the Docker commands, but you also can use IntelliJ to do every necessary operations. You need to install the Docker plugin and connect it to your Docker process. If you use Ubuntu, you need only to select the option”Unix socket” on the Docker configuration page, test the connection, and you are ready to go.
- Although the course described, how to use the Fabric8 plugin, it is not really an option for me, while it does not supports higher versions Java versions, than 1.8. As I use Java 11 for my projects, I had to find another way to deploy my application as Docker image.
My next step will be to learn how to deploy my application and other required components to a cloud provider (AWS or Google) and use them from there.