Goodbye command line! One-click deployment of applications to remote servers, IDEA official Docker plugin is really fragrant!
As the current mainstream container technology, Docker is very convenient to use it to deploy applications! For this mainstream container technology, IDEA officially supports it. I recently experienced a plug-in provided by IDEA, which is really easy to use. Today we take the packaging and deployment of SpringBoot applications as an example to talk about the use of IDEA's official Docker plug-in!
SpringBoot actual e-commerce project mall (50k+star) address: https://github.com/macrozheng/mall
- Since this plugin is IDEA's built-in plugin, it is enough to enable it directly in the plugin settings;
- Since our Docker environment is deployed on a remote server, we also need to configure the connection information of Docker, which can be configured in the Docker settings. When you see the
连接成功prompt, it means that the configuration is correct;
- Next, open the
Servicespanel at the bottom of IDEA, and double-click the Docker icon to connect. After the connection is successful, you can manage the Docker containers and images on the remote server.
- Click the
Imagesbutton, enter the name and version number of the image to be downloaded, and you can download the image. IDEA also supports automatic prompts, which is so sweet!
- Right-click the specified image to open the menu, and we can also perform conventional operations such as creating containers, viewing, and deleting them;
- Of course, we can also use Dockerfile to build our own image, here is my mall-tiny scaffolding project as an example, first prepare the Dockerfile script;
# 该镜像需要依赖的基础镜像 FROM java:8 # 将当前目录下的jar包复制到docker容器的/目录下 ADD ./mall-tiny-1.0.0-SNAPSHOT.jar /mall-tiny-1.0.0-SNAPSHOT.jar # 声明服务运行在8080端口 EXPOSE 8080 # 指定docker容器启动时运行jar包 ENTRYPOINT ["java", "-jar","/mall-tiny-1.0.0-SNAPSHOT.jar"] # 指定维护者的名字 MAINTAINER macrozheng
- Then open the Dockfile file, click the left button and select Create a new run configuration;
- Next, select the remote Docker service we configured, and configure the application packaging directory and image name;
- Then select the package image, the console will output the following log, the jar package will be directly uploaded to the remote server and packaged into an image.
- Right-click the image to open the menu, and you can also create a container directly;
- Since the mall-tiny project needs to use mysql and redis services, we can start them first;
- Then modify the configuration of the created container, mainly some of the configurations specified before using the
- You can directly compare the
docker runcommand used before, and you can probably know the function of these configurations;
docker run -p 8080:8080 --name mall-tiny \ --link mysql:db \ --link redis:redis \ -e 'spring.profiles.active'=prod \ -v /etc/localtime:/etc/localtime \ -v /mydata/app/mall-tiny/logs:/var/logs \ -d mall-tiny/mall-tiny:1.0.0-SNAPSHOT
- During the running process, you can directly view the running log of the container in the
Logtag, which is really convenient!
interact with the container
- Through the container panel, we can view a lot of container internal information, such as viewing environment variables;
- You can also view the port mapping configuration of the container;
- You can also view the information obtained by the
docker inspectcommand before, such as viewing the IP address of the container running;
- You can also directly enter the container to execute the command. Remember the
docker exec -itcommand used before.
Docker Compose support
- Using this plug-in, you can also deploy the application through Docker Compose. First, create the
docker-compose.ymlfile. Since the mysql container is not created with Docker Compose, IP is used instead to access;
version: '3' services: redis: image: redis:5 container_name: redis-tiny command: redis-server --appendonly yes volumes: - /mydata/redis-tiny/data:/data #数据文件挂载 ports: - 6379:6379 mall-tiny: image: mall-tiny/mall-tiny:1.0.0-SNAPSHOT container_name: mall-tiny links: - redis:redis depends_on: - redis ports: - 8080:8080 environment: - 'spring.profiles.active=prod' - 'spring.datasource.url=jdbc:mysql://192.168.3.105:3306/mall_tiny?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false' - 'spring.redis.host=redis' volumes: - /etc/localtime:/etc/localtime - /mydata/app/mall-tiny/logs:/var/logs
- Then directly click the
docker-compose.ymlfile arrow to deploy the application to the remote server, which is really convenient!
- After the deployment is complete, you can access the Swagger page of the project. Access address: http://192.168.3.105:8080/swagger-ui/
Today, I experienced an official Docker plug-in of IDEA, which can manage remote Docker images and containers without using the command line. It also supports Docker Compose deployment, which is really powerful! In the usual development process, it is really convenient to use this plug-in to package, deploy, and run SpringBoot applications. Interested partners can try it!
Official documentation: https://www.jetbrains.com/help/idea/docker.html