Docker Deployment: Spring Boot Image
This section will help you build and deploy a Spring Boot Docker Image. The steps provided here are what the current automation sh script does. Documenting the script might help future improvements and/or migration to a more sensible pipelines.
This section uses the ff:
- a local private docker registry
- a local docker daemon deployed at a Virtual Machine
Before proceeding, one must assume the ff. directory structure:
├─ parent directory
├─ java/Dockerfile # Where the Dockerfile for Spring boot builds will happen.
├─ output/ # Where your API will be pulled
-
Clone the repository - For automation purposes, the project repository is always cleaned to avoid possible remnants that might interfere with the process.
-
Set Docker Host - To be able to target your remote docker daemon, you must set the
DOCKER_HOSTusing the ff. command:
export DOCKER_HOST=tcp://192.168.100.63:2375 # sample docker host
info
- If deploying locally, you may skip this step.
- Ensure that your docker host allows remote connection.
- Build the docker image - Next, we're going to build the docker image. with the ff. command:
docker build --build-arg JAR_NAME=${JAR_NAME} --build-arg PROJECT_PATH=${PROJECT_PATH} -t ${PRIVATE_REGISTRY}/${ORG_NAME}/${IMAGE_NAME} -f java/Dockerfile . --progress=plain
# docker build - basic command to build the docker image
#
# --build-arg KEY=VALUE - supply an environment variable to the build process. ff. are the env. vars:
# > JAR_NAME=${JAR_NAME} - name of the jar found in build/outputs folder.
# > PROJECT_PATH=${PROJECT_PATH} - in this case, the project path is different from where the `Dockerfile` is located.
#
# -t ${PRIVATE_REGISTRY}/${ORG_NAME}/${IMAGE_NAME} - tag this image to the private registry.
# -f java/Dockerfile - path to the `Dockerfile`
# . - the context path to where the current build will happen. Set on the parent directory of both `java/Dockerfile/` and `PROJECT_PATH`.
- Push your Docker Image to Registry (Optional) - Pushing your image to a private (or public) docker registry will ensure that your image will be available to a different docker environment.
Take note that although we've build the docker image remotely, it will only be available at the said remote docker daemon itself.
docker image push ${PRIVATE_REGISTRY}/${ORG_NAME}/${IMAGE_NAME}
- Deploy your application via Portainer UI - Coming soon.