Process analysis of publishing spring boot project with docker compose image


brief introduction

Docker compose project is the official open source project of docker, which is responsible for the rapid arrangement of docker container clusters. Compose allows users to define a set of associated application containers as a project through a separate docker-compose.yml template file (yaml format). The docker compose project is written in Python and calls the API provided by the docker service to manage the container. Therefore, as long as the operating platform supports docker API, composition can be used for orchestration management.

Docker compose divides the managed containers into three layers: project, service and container. All files (docker-compose.yml, extensions files or environment variable files, etc.) in the docker compose running directory form a project. Unless otherwise specified, the project name is the current directory name. A project can contain multiple services. Each service defines the image, parameters and dependencies of the container. A service can include multiple container instances. Docker compose does not solve the problem of load balancing. Therefore, it is necessary to use other tools to realize service discovery and load balancing.

The project configuration file of docker compose is docker-compose.yml by default. You can use the environment variable compose_ The file or – f parameter defines a custom configuration file that defines multiple dependent services and the container in which each service runs.
Using a dockerfile template file allows users to easily define a separate application container. In work, we often encounter the situation that multiple containers need to cooperate with each other to complete a task. For example, to implement a web project, in addition to the web service container itself, you often need to add the back-end database service container, and even the load balancing container.

Common commands



Compose is used to “define and run applications of multiple docker containers”. With compose, you can configure your application services in a configuration file (yaml format), and then use a command to create and start all services referenced in the configuration.
Two important concepts in compose:
• service: an application container can actually include several container instances running the same image.
• project: a complete business unit composed of a group of associated application containers, which is defined in the docker-compose.yml file.

Installation of docker compose

There are many ways to install compose. This article explains how to install through shell. Other installation methods, if interested,
You can view the official docker documentation:

Installation steps of docker compose

Download and install non root users through the GitHub link. Remember to add sudo

sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Executable permissions for binary download files

sudo chmod +x /usr/local/bin/docker-compose

Verify installation

docker-compose --version

If it is installed in binary package mode, delete the binary file

rm /usr/local/bin/docker-compose

directory structure



The use of compose is very simple. You only need to write a docker-compose.yml, and then use the docker-compose command to operate. Docker-compose.yml describes the configuration of the container, while the docker-compose command describes the operations on the container.
1. Let’s use a microservice project to make a simple example. First, create a work directory of compose, and then create a jenkinstest folder with executable jar packages and a dockerfile file. The directory structure is as follows:
Jenkins stores its own test uploaded jar package



Version: '3.1' # here you need to specify the docker version corresponding to docker compose
  Jenkinstest: # specify the service name
    #Image: jenkinstest # specifies that the image name is lowercase, otherwise an error will be reported
    Build:. / jenkinstest # specifies the path where the dockfile is located
      -8099:8099 # specify port mapping
      -8099 # exposed service port

Dockerfile file

FROM adoptopenjdk/openjdk8:jdk8u-centos-nightly


#Mirror the ports to be exposed. If you want to use ports, use - P to take effect when executing the docker run command
COPY jenkinsTest.jar 11.jar 
#Commands executed after the mirror is run as a container
ENTRYPOINT ["java","-jar","11.jar"]

Start the microservice, which can be started in the background with the parameter – D

docker-compose up -d


Choreograph spring cloud microservices using docker compose

The configuration is the same as above
Modify the docker-compose.yml file

version: '3.3'
    Image: Eureka: V1 # specify the image name
    Build:. / Eureka # specifies the path where the dockfile is located
     - 8080:8080
    image: user:v1
    Build:. / user # specifies the path where the dockfile is located
     - 8081:8081
    image: power:v1
    Build:. / power # specifies the path where the dockfile is located
     - 8082:8082

This is the end of this article about the process analysis of docker compose image publishing springboot project. For more information about docker compose publishing springboot project, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!