IDEA plug-in Docker combat (Docker-compose articles)

This article is "IDEA plug-in Docker combat" the third in the series, IDEA plug-in Docker There are three: Dockerfile, Docker Image, Docker-compose, in front of us are familiar with the Dockerfile, Docker Image, today to combat Docker-compose.

Series link

  1. "IDEA plug-in Docker combat (Dockerfile articles)" ;
  2. "IDEA plug-in Docker combat (Docker Image articles)" ;
  3. "IDEA plug-in Docker combat (Docker-compose articles)" ;

Development environment

  1. Development Environment Operating System: macOS Mojave
  2. IntelliJ IDEA: 2018.3.5 (Ultimate Edition)
  3. Docker Environmental Services is located: Ubuntu 18.04.2 LTS
  4. Docker:19.03.1(Community)

Note: IEDA host computer should install Docker and docker-compose

Ready to work

Docker remote services built on IDEA connected, as shown, connected IEDA Docker service deployed on 192.168.50.75 IP server is:
Here Insert Picture Description
Note: Remote Docker located on the computer, and at this time there is no image Docker containers, empty

Use Docker-compose plug

The role of the plug-in is relatively simple: let container remote Docker run the specified docker-compose.yml choreography;

接下来的实战会创建一个docker-compose.yml,里面编排了三个容器:Nacos、simple-provider、simple-consumer,这三个容器组成了spring-cloud-alibaba的注册中心体验环境,其功能如下图所示:
Here Insert Picture Description
本文不会对上述功能的细节做过多描述,如果您对上图的镜像的细节感兴趣,可以参考《Docker下,两分钟极速体验Nacos》

准备工作已完成,可以开始实战:

  1. 新建一个maven工程;
  2. 在pom.xml文件所在目录创建文件docker-compose.yml,内容如下:
version: '2'
services:
  nacos:
    image: bolingcavalry/nacosserver:0.0.1
    container_name: nacos
    restart: always
    ports:
      - '8848:8848'
  provider:
    image: bolingcavalry/nacossimpleprovider:1.0-SNAPSHOT
    links:
      - nacos:nacoshost
    depends_on:
      - nacos
    restart: always
  consumer:
    image: bolingcavalry/nacossimpleconsumer:1.0-SNAPSHOT
    links:
      - nacos:nacoshost
    container_name: consumer
    depends_on:
      - nacos
    ports:
      - '8080:8080'
    restart: always
  1. 点击下图红框中的"Edit Configurations",新建一个配置:
    Here Insert Picture Description
  2. 如下图,新建一个Docker-compose配置:
    Here Insert Picture Description
  3. 在新的配置页面,填写下图所示的信息:
    Here Insert Picture Description
  4. 在主窗口选中刚才的配置,点击下图红框2中的绿色三角形,开始执行此配置:
    Here Insert Picture Description
  5. 如下图所示,由于Docker所在机器上没有docker-compose.yml中指定的镜像,因此会立即开始下载:
    Here Insert Picture Description
  6. 启动成功后,主窗口信息如下:
    Here Insert Picture Description
  7. 验证容器服务是否正常,Docker所在服务器IP地址是192.168.50.75,所以访问地址:http://192.168.50.75:8080/test ,如下图,响应数据证明三个容器都是正常的(第二行数据来自provider返回给consumer的):
    Here Insert Picture Description
  8. 除了运行docker-compose.yml中的所有容器,Docker-compose插件还能指定服务运行,再新建一个Docker-compose配置,使用相同的docker-compose.yml文件,和前面不同的是service这里填入的是其中的一个"provider":
    Here Insert Picture Description
  9. Run this new configuration, visible only to re-run the provider:
    Here Insert Picture Description
    At this point, Docker plug-in series is completed, I hope the article will give you some reference to help you more skilled use this plug-in.

I welcome the attention of the public numbers: programmer Chen Xin

Here Insert Picture Description

Published 328 original articles · won praise 946 · Views 1.17 million +

Guess you like

Origin blog.csdn.net/boling_cavalry/article/details/100064934