Docker-compose image release process analysis of springboot project

Docker-compose image release process analysis of springboot project

Introduction

The Docker-Compose project is an official open source project of Docker, responsible for realizing the rapid orchestration of Docker container clusters. Compose allows users to define a group of related application containers as a project through a single 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 containers. Therefore, as long as the operating platform supports the Docker API, Compose can be used on it for orchestration management.

Docker-Compose divides the managed containers into three layers: project, service, and container. All files in the Docker-Compose running directory (docker-compose.yml, extends files or environment variable files, etc.) form a project. If no special project name is specified, the current directory name is used. A project can contain multiple services, and each service defines the image, parameters, and dependencies of the container running. A service can include multiple container instances. Docker-Compose does not solve the problem of load balancing, so other tools are needed to achieve service discovery and load balancing.

The default project configuration file of Docker-Compose is docker-compose.yml. You can customize the configuration file through the environment variable COMPOSE_FILE or the -f parameter. It defines multiple dependent services and the containers running each service.
Using a Dockerfile template file allows users to easily define a separate application container. At work, we often encounter situations where 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, it is often necessary to add a backend database service container, and even a load balancing container.

Common commands

docker-compose

introduce

The role of Compose is to "define and run applications in multiple Docker containers." With Compose, you can configure your application's services in a configuration file (yaml format), and then use a single command to create and start all the services referenced in the configuration.
There are two important concepts in Compose:
• Service: A container for an application can actually include several container instances running the same image.
• Project: A complete business unit consisting of a set of associated application containers, defined in the docker-compose.yml file.

Installation of Docker Compose

There are many ways to install Compose. This article explains how to install it through the shell. If you are interested in other installation methods,
You can view the official Docker documentation: https://docs.docker.com/compose/install/

Docker Compose installation steps

Download and install through GitHub link. Non-ROOT users remember to add sudo

sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Give executable permissions to the binary download file

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

Verify installation

docker-compose --version

Uninstall If it is installed as a binary package, just delete the binary file

rm /usr/local/bin/docker-compose

Directory Structure

compose
	docker-compose.yml
	eureka
		Dockerfile
		eureka-server-2.0.2.RELEASE.jar
	user
		Dockerfile
		user-2.0.2.RELEASE.jar
	power
		Dockerfile
		power-2.0.2.RELEASE.jar

Example

Compose is very easy to use. You only need to write a docker-compose.yml file and then use the docker-compose command. docker-compose.yml describes the configuration of the container, while the docker-compose command describes the operation of the container.
1. Let's use a microservice project as a simple example. First, create a compose working directory, then create a jenkinsTest folder, put the executable jar package and write a Dockerfile file. The directory structure is as follows:
Jenkins stores the jar packages uploaded for your own tests

insert image description here

docker-compose.yml

version: '3.1' #Here you need to specify the docker version corresponding to docker-compose services:
  jenkinstest: #Specify the service name#image: jenkinstest #Specify the image name in lowercase otherwise an error will be reportedbuild: ./jenkinsTest #Specify the path where the Dockfile is locatedports:
      - 8099:8099 #Specify port mapping expose:
      - 8099 #Exposed service port

Dockerfile

FROM adoptopenjdk/openjdk8:jdk8u-centos-nightly

#AuthorMAINTAINER lkz

# The port to be exposed by the image. If you want to use the port, use -p to take effect when executing the docker run command EXPOSE 8099
 
COPY jenkinsTest.jar 11.jar 
# Command executed after the image runs as a container ENTRYPOINT ["java","-jar","11.jar"]

To start the microservice, you can add the parameter -d to start it in the background

docker-compose up -d 

insert image description here

Orchestrate SpringCloud microservices using Docker Compose

Modify the docker-compose.yml file as above

version: '3.3'
services:
  eureka:
    image: eureka:v1 #Specify the image name build: ./eureka #Specify the path where the Dockfile is located ports:
     - 8080:8080
  user:
    image: user:v1
    build: ./user #Specify the path where Dockfile is located ports:
     -8081:8081
  power:
    image: power:v1
    build: ./power #Specify the path where Dockfile is located ports:
     -8082:8082

This is the end of this article about the process analysis of docker-compose image publishing springboot project. For more relevant docker-compose publishing springboot project content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to publish Docker images to Docker Hub
  • How to configure docker in IDEA2021.2 to image the springboot project and release it with one click
  • How to publish a locally built docker image to dockerhub
  • Detailed steps for building, running, publishing, and obtaining a Docker image for the first time
  • How to use Docker to publish local images to Alibaba Cloud

<<:  DHTML objects (common properties of various HTML objects)

>>:  Implementation of MYSQL (telephone number, ID card) data desensitization

Recommend

Eight ways to implement communication in Vue

Table of contents 1. Component Communication 1. P...

Detailed explanation of Javascript Echarts air quality map effect

We need to first combine the air quality data wit...

MySQL derived table (Derived Table) simple usage example analysis

This article uses an example to describe the simp...

Explanation of the usage of replace and replace into in MySQL

MySQL replace and replace into are both frequentl...

How to migrate mysql storage location to a new disk

1. Prepare a new disk and format it with the same...

jQuery plugin to implement dashboard

The jquery plug-in implements the dashboard for y...

In-depth explanation of special permissions SUID, SGID and SBIT in Linux

Preface For the permissions of files or directori...

Detailed explanation of Vue lazyload picture lazy loading example

Documentation: https://github.com/hilongjw/vue-la...

Nginx reverse proxy to go-fastdfs case explanation

background go-fastdfs is a distributed file syste...

VUE implements bottom suction button

This article example shares the specific code of ...

VMware virtual machine installation Linux system graphic tutorial

This article shares the specific steps of VMware ...

Import CSS files using judgment conditions

Solution 1: Use conditional import in HTML docume...

Detailed explanation of SSH password-free login configuration under Linux

Assume there are two Linux servers A and B, and w...