Vaadin with Docker

Is there somewhere a good tutorial how to use Vaadin with Docker?

Hi Inez,

Compile your application to an app.
I am doing that with maven package -dproduction
and then take a simple apline docker file.
And tweak from there…

Docker file:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY target/rbac-generator-2.0-SNAPSHOT.jar /app.jar
ENTRYPOINT [“java”,“-Djava.security.egd=file:/dev/./urandom”,“-jar”,“/app.jar”]

Well, you don’t really “use Vaadin with Docker”. It’s more like “you deploy your Vaadin-based application to an application server running in a Docker container” so pretty much any tutorial would do.

Hm… I don’t want to use it only for deployment. I want to youse docker compose to set up mysql, a tomcat and then set up a smooth local development using the containers.

Ines Melzer:
Hm… I don’t want to use it only for deployment. I want to youse docker compose to set up mysql, a tomcat and then set up a smooth local development using the containers.

Yes but even if you build a stack with your tomcat and mysql, Vaadin is only relevant within a deployment. If you can deploy a simple HelloWorld.war you can deploy a HugeVaadinApp.war with the same procedure.

Ok, I want to create everything for development in docker containers. To keep it independent from the local machine.

This is my docker-compose.yml

version: '3.7'

services:
  wep-app:
    build:
      context: ./
      dockerfile: Dockerfile-build
    image: wgportal
    ports:
      - 8080
    links:
      - node  
    networks:
      - frontend
     
    
  
  db:
    image: mysql:5.7
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_DATABASE: azubi-wgportal
      MYSQL_USER: user
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: root
    networks:
      - backend
  
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: portal_phpmyadmin
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
      ports: 8080
      links: db

  node:
    image: "node:10.16.3-slim"
    user: "node"
    working_dir: /home/node/app
    environment:
      - NODE_ENV=production
    volumes:
      - ./:/home/node/app
    expose:
      - "8081"
    command: "npm"
    
# Networks to be created to facilitate communication between containers
networks:
  backend:
  frontend: 

And my Dockerfile-build:

FROM maven:3.6.2-jdk-8-slim
COPY docker/settings.xml /usr/share/maven/conf/settings.xml
WORKDIR /usr/src/java-code
COPY . /usr/src/java-code/
RUN mvn clean package -X

WORKDIR /usr/src/java-app
RUN cp /usr/src/java-code/target/*.jar ./app.jar
EXPOSE 8080
CMD ["java", "-jar", "app.jar"]

If I run docker-compose up, I’ll get the error: Failed to determine ‘node’ tool.

How can I connect the node and the mvn-build?

Are you building your application in an docker? That’s is going a big docker…
and it needs nodejs to build.

The best practice is building a small and fast docker.

Personally I deploy to a WildFly with a maven plugin to the admin port but I guess you could also expose the tomcat deployment directory to the host and just build/deploy to that folder(?)

joe doe:
Are you building your application in an docker? That’s is going a big docker…
and it needs nodejs to build.

The best practice is building a small and fast docker.

So, what is your preference to do that? or the best practice for build and deploy vaadin app in docker.

You can make a development enviroment in the docker.

But what I am doing in production is building the application and adding a java wrapper. Look at my fist post.
In the production you want to have a fast starting application. And my production is in Kubernetes.

You can make a development enviroment in the docker.

But what I am doing in production is building the application and adding a java wrapper. Look at my fist post.
In the production you want to have a fast starting application. And my production is in Kubernetes.

Compatible docker image for building is very important.
Because it is required for building Vaadin App through Jenkins pipeline.
For vaadin 8 which required only maven, it worked like a charm:

pipeline 
{
    agent { docker 'maven:3.5.4' }
...
    stages 
    { 
        stage('checkout')
        {
		...
        stage('build') 
        {
            steps 
            {
                sh 'echo build'
                sh 'mvn --version'
                sh 'mvn -f jet.webapp.pom.xml -s settings.xml -Partifactory,repo1 -B -DskipTests clean install'
            }
        }
		...

For vaadin 10, we would need an official image from vaadin because maven is not enough !

You need node.js available to build. Build in production mode, then you can deploy in any way you want. But you need node.js to build. In order to get node.js, there are several ways – use an image that already has it, OR get your maven to install it to your docker.

If you pick the second avenue, here is a recipe to get you started in building it – it includes the recipe in the “heroku” provide to download and run node.js from the maven build. https://github.com/mvysny/vaadin14-embedded-jetty