[2/3] Push the Spring Boot App Docker Image to Docker Hub and Deploy to Digital Ocean’s Droplet

İlker Güldalı
5 min readApr 9, 2022

👋 Hi everyone!

👉[2/3] — Push the Spring Boot App Docker Image to Docker Hub and Deploy to Digital Ocean Droplet
We’ll learn how to push previously locally created image to Docker Hub and simple way to deploy Digital Ocean Droplet.

Things we will fully experience with this series of articles:
✔️[1/3] — Let’s Create a Spring Boot App With MySQL, Docker, Docker Compose
We will examine how to use Docker and Docker Compose on a Spring Boot — MySQL application and what adjustments are required.

👉[2/3] — Push the Spring Boot App Docker Image to Docker Hub and Deploy to Digital Ocean Droplet
We’ll learn how to push previously locally created image to Docker Hub and simple way to deploy Digital Ocean Droplet.

✔️[3/3] — Deploy the Spring Boot App which is using Docker and Docker Compose in through “Github Actions” to a Droplet
By implementing CI/CD processes into our project, we will experience making things a little easier.

In the previous article, we created our “Bored app” using Docker and Docker Compose. In this article, we will examine how to send the image file we created to Docker Hub and run it in the droplet in Digital Ocean.

Let’s start!

🍄Pushing the Docker Image to Docker Hub

In the previous article, we named the docker image as “ilkerguldali/boredapp:latest” in the docker-compose.yml file. Judging by the details in the name; It can be said as <docker-hub-username>/<repo-name>:<tag>. In order for an image file to be pushed to Docker Hub, its name must be in this structure. In cases where the <tag> parameter is not added, it works via the “latest” tag by default.

In summary, by re-tagging, we can make the image file in the local ready to be push, or this can be done by giving a name to the image file while building.

docker tag <existing-image> <hub-user>/<repo-name>[:<tag>]

After making the name of the image file ready, all that remains is to login via the Docker CLI.

docker login
login command output

Finally, we push the image file in the local environment to our account in Docker Hub with the docker push command.

docker push ilkerguldali/boredapp:latest
push command output

Congrats ✨ The image file has now been pushed to the Docker Hub account, available for public download.

hub.docker.com homepage view

🧗‍♂️Creating Droplets on Digital Ocean

A new Droplet is created from the “Droplets” page after registering with Digital Ocean.

DigitalOcean Droplets are Linux-based virtual machines (VMs) that run on top of virtualized hardware. Each Droplet you create is a new server you can use, either standalone or as part of a larger, cloud-based infrastructure.

We can create a Droplet with the Ubuntu operating system from the Distributions tab, then we can install Docker in it. Instead of doing this, it is possible to install an Ubuntu with Docker directly from the Marketplace tab.

Droplet creation page detail

Then the appropriate plan is selected and the authentication method should be set. Here, if you want to connect to Droplet via the SSH Keys in your Digital Ocean account, you can select the appropriate keys. Otherwise, continue with the Password option.

By connecting via SSH with the IP address of the Droplet, we can check whether the Droplet has been created successfully or not.

ssh command output

More detailed information on creating a droplet can be found on the docs page.

💡Running Spring Boot Application on Droplet

If the image file on Docker Hub is private, docker login must be done on Droplet first.
Before sending the docker-compose.yml file in the local environment to Droplet, a folder is opened in the main directory. The file is copied into this folder with the command below.

scp .\docker-compose.yml root@<droplet-ip>:/<app-name>/docker-compose.yml
scp command output

Then the pull command is run to download the images in the docker-compose.yml file.

docker-compose pull command output

Finally, with the up command, the images in the yml file are run with the relevant configurations.

docker-compose up command output

In order to see that the “Bored App” Spring Boot application is running successfully, the logs of the container can be examined with the help of the command below.

docker logs --follow bored-spring

After the --follow parameter, the container name to be monitored should be given. This parameter corresponds to the “container_name” parameter in the docker-compose.yml file. In addition, container names can be viewed with the docker pscommand.

docker logs command output

When the port address of the Spring Boot application is added to the IP address of the Droplet, we can see that the application is running actively🎊

Live state of the application after deployment

🧿Conclusion

In this article, I explained how to send a docker image file created in the local environment to Docker Hub and how to run it in the Digital Ocean Droplet.

I hope I can bring the continuation of the article series mentioned at the beginning of the article. Each like is a “Yes! You can” support. This is the second post, only 2 more posts left 🙊

Thanks for reading, 💃🏻have fun coding!

🕌Ramadan mubarak!

References

--

--