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

Several situations where div is covered by iframe and their solutions

Similar structures: Copy code The code is as foll...

Nest.js hashing and encryption example detailed explanation

0x0 Introduction First of all, what is a hash alg...

Detailed explanation of Vue data proxy

Table of contents 1. What I am going to talk abou...

How to view the IP address of Linux in VMware virtual machine

1. First, double-click the vmware icon on the com...

A summary of some of the places where I spent time on TypeScript

Record some of the places where you spent time on...

The most detailed method to install docker on CentOS 8

Install Docker on CentOS 8 Official documentation...

CSS sets the list style and creates the navigation menu implementation code

1. Set the list symbol list-style-type: attribute...

Linux system AutoFs automatic mount service installation and configuration

Table of contents Preface 1. Install the service ...

Build nginx virtual host based on domain name, port and IP

There are three types of virtual hosts supported ...

Build a Scala environment under Linux and write a simple Scala program

It is very simple to install Scala environment in...

The process of quickly converting mysql left join to inner join

During the daily optimization process, I found a ...

Detailed analysis of classic JavaScript recursion case questions

Table of contents What is recursion and how does ...

In-depth understanding of the vertical-align property and baseline issues in CSS

vertical-align attribute is mainly used to change...

Linux beginners in virtual machines configure IP and restart the network

For those who are new to virtual machines or have...