IDEA quickly implements Docker image deployment and operation (for mac M1)

background

How to install docker on mac m1 can be found in my previous article. Mainly after changing to mac, for example, idea connects to docker, realizes the process of packaging jar from idea on maven, cooperates with dockfile to operate docker to build the image, creates the container, and runs the container. That is, the process that can be implemented on an idea, developed, packaged, deployed to a remote server and run.

How to enable docker remote connection service

Allow idea to access and operate docker.
The mac-based docker for mac itself does not support remote access and needs to rely on the image provided by a network tool called socat for remote access.

non-container mode

Install socat: brew install socat
Run socat:

#打开独立的新Terminal,执行启动socat,一直保持该窗口,不用管.
socat -d TCP-LISTEN:2375,range=127.0.0.1/32,reuseaddr,fork UNIX:/var/run/docker.sock 
#如果要后台运行,懒得打开新的Terminal,使用 nohup terminalCMD &
#示例: 
# nohup socat -d TCP-LISTEN:2375,range=127.0.0.1/32,reuseaddr,fork UNIX:/var/run/docker.sock &

Don't close the window.
Open a new terminal and enter: curl http://localhost:2375/info. The following appears, indicating success
Insert image description here

Container mode

Reference: https://blog.csdn.net/qq_31493821/article/details/118371562
Pull: docker pull alpine/socat
This command is taken from the socat description on the docker official website
. Startup command:

			docker run -d --restart=always \
			    -p 127.0.0.1:2376:2375 \
			    -v /var/run/docker.sock:/var/run/docker.sock \
			    alpine/socat \
			    tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock

Visit: http://127.0.0.1:2376/info. If a json description with detailed information appears, there will be no problem.
ps: This method is not recommended because a warning message is displayed on the docker interface, saying that socat m1 is not supported. . Crash easily. But if you use the above method, you have to enter the command every time, and it cannot be closed. It is definitely not as comfortable as the docker interface operation.

idea connect docker

Insert image description here
There is no need to enter anything except the name, it is just fine.
At this time, right-click the Docker connection you just established in the service window, click connect, and
you can see the container, image and operate it.
Insert image description here

ConfigureDockfile

This configuration file describes what is needed to build the image.

#FROM openjdk:8u212-jre
FROM azul/zulu-openjdk-alpine

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"]

ps: The previous jdk image failed to be pulled. I found the azul/zulu-openjdk-alpine image from the docker official website. I don’t know if it supports m1. It can be packaged normally, but the package will prompt that it is compatible with m1. question. . .

Configure docker's running configuration

Implement packaging, build images, publish docker, create containers and run them.
Insert image description here
ps: There is a paragraph below the picture. You need to configure and recompile the packaging project before running docker run: clean package -U -DskipTest -P test

Run configuration

The running configuration can see the entire log trace of packaging, building images, publishing docker, creating containers and running them.

other

How should the web project in docker be configured to access the host's mysql?
During the actual test, the container accesses the host mysql, and the host address is 127.0.0.1. The
host accesses the container in docker, and the page enters 127.0.0.1 and adds the configured mapped port.

Guess you like

Origin blog.csdn.net/mofsfely2/article/details/119584171