In the following example, I will use a (ridiculously) basic Spring Boot app. The app is a simple REST web app that outputs the following plain test "Hello Docker World!". The app is running on Tomcat on port 8080 and is packaged as a jar file. The project was named "docker-demo" and the jar file is named "docker-demo".
- Docker Desktop
- Java 17 or higher
- An existing Spring Boot app
docker build --platform linux/amd64 -t docker-demo .
docker run -d --rm --name innolab -p 8088:8080 -t docker-demo
-d (aka --detach) Runs container in background and prints container ID. The container needs to be stopped with the Docker Desktop or the docker stop [CONTAINER ID] command.
--rm Automatically remove the container when it exits [optional]
--name Assign a name to the container [optional]
-p Publish a container's port(s) to the host. In this case, browsing to port 8088 will redirect to tomcat exposed 8080.
-t Help page says: "Allocate a pseudo-TTY". Not actually correct. This indicates the name of the image to run. [REQUIRED]