Containerize Spring Boot App with Docker

  • Add docker maven plugin to pom.xml
  • Create Dockerfile at the root of the project
FROM openjdk:8-jdk-alpine
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
  • Build docker image

mvn clean install dockerfile:build

  • Login to docker hub and push the image to docker hub (Optional Step)

docker login -u <username>
mvn dockerfile:push

  • Verify the image is built and available

docker images

  • Run Spring Boot App from docker

docker run –rm -d –restart -p 8080:8080 ${docker.image.prefix}/${project.artifactId}

Deploy Flask Application to Apache Webserver

  • Install mod_wsgi

sudo apt-get install libapache2-mod-wsgi

  • Enable wsgi module

sudo a2enmod wsgi

sudo systemctl restart apache2

  • Create .wsgi file with below content

from yourapp import app as application

  • Configure a new site in Apache2
    ServerName site.api

    WSGIDaemonProcess site user=www-data group=www-data threads=5 home=/var/www/site
    WSGIScriptAlias / /var/www/site/app.wsgi

    <Directory /var/www/site>
        WSGIProcessGroup site
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all

    WSGIPassAuthorization On

  • Enable the site and reload Apache2

DevOps Consultant