Detailed explanation of the latest IDEA process of quickly deploying and running Docker images

Detailed explanation of the latest IDEA process of quickly deploying and running Docker images

background

Use idea with docker to realize the whole process from javaweb development, deployment, and operation.
Environment: configured docker, installed mysql8 container, a springBoot framework web project (with swagger for easy testing)

Open Docker remote connection

The online method cannot find the corresponding docker.service file, maybe the version or installation method is different.
Find the location of the docker.service file through systemctl status docker:

insert image description here

Modify the /etc/systemd/system/docker.service file:

#ExecStart=/usr/bin/dockerd
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

Restart the Docker service:

systemctl daemon-reload 
systemctl restart docker.service

Port 2375 is open:

firewall-cmd --zone=public --add-port=2375/tcp --permanent
firewall-cmd --reload

After restarting, verify whether port 2375 is accessible:
http://192.168.137.188:2375/info

insert image description here

Note: This indicates success.

idea docker plugin configuration

idea 2019 version 3 has integrated docker. If it is not integrated, please install it yourself.

insert image description here

Note: docker - After clicking "+", fill in the connection name and Linux host IP: docker external port

Connect idea to docker and familiarize yourself with the available operations on the relevant interface:

insert image description here

Note: It integrates common commands including containers and basic images. You can study their specific usage by yourself, which is not difficult.

Add Dockerfile to SpringBoot Application

insert image description here

Note: The same directory as the pom file, the file contents are as follows:

FROM openjdk:8u212-jre
MAINTAINER aliyu<[email protected]>

COPY target/myframe-0.0.1-SNAPSHOT.jar /myframe-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "/myframe-0.0.1-SNAPSHOT.jar"]

Add docker run configuration

insert image description here

Note: 1. Right click "edit configuration"
2. Click "+" and select docker
3. Select the docker connection defined earlier
4. Name of Dockerfile
5. Directory location of dockerfile
6. Project image and version definition
7. Check run build image and name the container so that you can create and run the container after creating the image.
8. Configure port mapping between host and container
9. Configure a fixed IP for the container to avoid the problem of similar projects not being able to find services due to random IP. For fixed IP configuration, please refer to: http://blog.java1234.com/blog/articles/628.html
ps: The default IP address of the mysql8 container has been configured to be in the same network segment as the IP address here.
10. You can preview the command here to check for errors.
11. Before configuring and running docker run, you need to recompile the packaged project:

clean package -U -DskipTest -P test

Note: During development, the host accesses the MySQL container in Linux, and when the application is generated as a container runtime, the application container accesses the MySQL container. The mysql configuration in yml is inconsistent, so the test yml configuration file is used specifically for docker deployment. ps: For containers to access each other, please check the "Others - Communication between containers" title. After it is created, you can see:

insert image description here

Note: There is one more dockerFile to start

Run docker startup configuration

Click:

insert image description here

Note: You can see the complete process of Maven clean packaging, as well as the process of Docker building images, creating and starting containers. You can even see the logs of the container startup project

Test access to the swagger homepage:

insert image description here

other

Communication between containers

Background: Because I don’t understand how containers communicate with each other, when configuring MySQL connection, the URL is always wrong and database connection problems are always reported.

The host IP plus the mapped port can access the mysql8 container:
url: jdbc:mysql://192.168.137.188:3307/db_myframe?serverTimezone=GMT

However, accessing the myframe container through the host IP plus the mapped port fails because the communication between containers is different

It cannot be accessed through localhost:3306. The localhost in the docker container does not refer to the localhost of the host machine.

Docker creates a virtual network card at runtime and names it docker0
Use docker inspect mysql8 to find the IP address 172.17.0.2. However, note that when accessing containers, the port must be the port in the container, not the port mapped to 3307 on the host.

This is the end of this article about the latest IDEA to quickly implement Docker image deployment and operation. For more related IDEA Docker image deployment and operation content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to configure docker in IDEA2021.2 to image the springboot project and release it with one click
  • idea combines docker to realize image packaging and one-click deployment
  • Intellij IDEA quick implementation of Docker image deployment method steps

<<:  How to check if a table exists in MySQL and then delete it in batches

>>:  SQL implements addition, subtraction, multiplication and division operations on two adjacent rows of data

Recommend

Complete steps for uninstalling MySQL database

The process of completely uninstalling the MySQL ...

Get the IP and host name of all hosts on Zabbix

zabbix Zabbix ([`zæbiks]) is an enterprise-level ...

Navicat Premium operates MySQL database (executes sql statements)

1. Introduction to Navicat 1. What is Navicat? Na...

N ways to cleverly implement adaptive dividers with CSS

Dividing lines are a common type of design on web...

Mobile front-end adaptation solution (summary)

I searched online and found that many interviews ...

MySQL common statements for viewing transactions and locks

Some common statements for viewing transactions a...

Detailed explanation of the marquee attribute in HTML

This tag is not part of HTML3.2 and is only suppo...

Robots.txt detailed introduction

Basic introduction to robots.txt Robots.txt is a p...

Detailed explanation of MySQL multi-table join query

Table of contents Multi-table join query Inner Jo...

Key knowledge summary of Vue development guide

Table of contents Overview 0. JavaScript and Web ...

Briefly understand the two common methods of creating files in Linux terminal

We all know that we can use the mkdir command to ...

The use of setState in React and the use of synchronous and asynchronous

In react, if you modify the state directly using ...

3 Tips You Must Know When Learning JavaScript

Table of contents 1. The magical extension operat...