Deploying Using Docker
A Docker container is a standalone, executable package of software that includes everything needed to run an application: Code, runtime, system tools, system libraries, and settings.
Building a Docker image requires creating a
Dockerfile which is a text document containing all the commands for assembling and running the image.
Creating a Dockerfile for New Vaadin Applications
For a new Vaadin application, you can generate a
Dockerfile by selecting the Docker config option in https://start.vaadin.com in the Settings tab.
This approach makes building and running your container as simple as running the following commands:
Run the following command to make a production build of the Vaadin application:
mvn clean install -Pproduction
Run the following command to build your container:
docker build . -t myapp:latestNote
The command assumes your project name is
myappwith the name of your project if it’s not.
run the following command to run your container on localhost:
docker run -p 8080:8080 myapp:latest
Docker Desktop or Docker Server is requiredYou need to install Docker Desktop or Docker Server on your machine before you can run the above commands.
Adding a Dockerfile to Existing Vaadin Applications
The following example shows a suitable Dockerfile for Spring Boot-based Vaadin applications. You get a similar file when you download a project from https://start.vaadin.com.
FROM openjdk:17-jdk-slim COPY target/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "/app.jar"]
Once you have a
Dockerfile in the project directory, you can build and run your container using the
docker build and
docker run commands shown earlier.
You can find more information on
Dockerfile and the instructions that are available for it at https://docs.docker.com/engine/reference/builder/.