idea配置docker

目录

  1. 待用文件提取
  2. idea连接docker配置
  3. 配置dockerfile文件
  4. idea构建docker镜像并部署
  5. maven构建docker镜像并使用compose文件部署
  6. 问题总结
待用文件提取
  1. 构建镜像semanteme/openjdk8u181:0.0.1文件提取
链接:https://pan.baidu.com/s/1rmjgU1AYhv5zoflY4foLQw 
提取码:4iy3
  1. pom文件提取
链接:https://pan.baidu.com/s/1ntamSPKZxPgsYgw6T5ORPw 
提取码:9y0w
  1. dockerfile文件提取
链接:https://pan.baidu.com/s/1sJ9joKih148c6gW8EjFvwg 
提取码:4c2q 
  1. compose文件提取
链接:https://pan.baidu.com/s/1r6cTru-XniIYgsQaxXrT0Q 
提取码:gvgv
一:idea连接docker配置
  1. 修改配置文件,打开2375端口
vi /usr/lib/systemd/system/docker.service

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

systemctl daemon-reload

systemctl restart docker

在这里插入图片描述
2. file->setting->plugins 安装docker插件
在这里插入图片描述
3. file->setting->docker设置连接配置
在这里插入图片描述

配置dockerfile文件
  1. 编写镜像部署dockerfile文件
FROM semanteme/openjdk8u181:0.0.1
MAINTAINER Semanteme <semanteme@126.com>
#ARG TAR_FILE
#ADD ${TAR_FILE} /
ADD cloud-agent-openstack-release.tar /
WORKDIR /cloud-agent-openstack
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dlogs.home=./logs","-Dlogging.config=./config/logback-spring.xml","-Dspring.config.location=file:./config/","-Dspring.pid.file=./logs/application.pid","-Dspring.pid.fail-on-write-error=true","-jar","./lib/cloud-agent-openstack.jar"]

在这里插入图片描述

idea构建docker镜像并部署
  1. idea构建服务包,根据dockerfile文件配置,服务包应与dockerfile在同一目录下
    在这里插入图片描述
  2. Edit Configurations配置构建与部署参数
    在这里插入图片描述
  3. 点击运行,构建镜像并部署
    在这里插入图片描述
maven构建docker镜像并使用compose文件部署
  1. 配置添加镜像构建的pom文件
<plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.4.13</version>
        <configuration>
            <!--注意imageName一定要是符合正则[a-z0-9-_.]的,否则构建不会成功-->
            <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
            <!-- 指定了Dockfile的目录,所以需要在项目的src/main下创建一个docker目录,并在其目录中配置Dockerfile文件 -->
            <dockerDirectory>${project.basedir}/docker</dockerDirectory>
            <resources>
                <resource>
                    <targetPath>/</targetPath>
                    <directory>${project.basedir}/docker</directory>
                    <include>${docker.image.resource.tar}</include>
                </resource>
            </resources>
            <imageTags>
                <imageTag>${docker.image.tag}</imageTag>
                <imageTag>latest</imageTag>
            </imageTags>
        </configuration>
    </plugin>
此处需设置DOCKER_HOST环境变量
此处需设置正确的配置参数
  1. 使用mvn命令构建docker镜像
mvn clean package -s "D:\Program Files\apache-maven-3.6.1\conf\settings_semanteme.xml" -Dmaven.test.skip=true -Denv=pro docker:build
  1. 使用compose文件部署
version: '3'
services:
  eureka:
    restart: always
    image: "semanteme/eureka:latest" # 镜像名:标签名
    hostname: eureka      # 注册中心的hostname一定要有,且必须和代码中配置文件里的hostname一致
    networks:
      - finance-net             # 加入的网络
    environment:
      - TZ=Asia/Shanghai
      - SLEEP_SECOND=4
    depends_on:
      - config
    ports:
      - "9091:9091"             # 映射的端口号,和代码中配置文件里的端口号一致
    tty: true
    entrypoint: /entrypoint.sh -d config:9093 -c 'java -Djava.security.egd=file:/dev/./urandom -Dlogs.home=./logs -Dlogging.config=./config/logback-spring.xml -Dspring.config.location=file:./config/ -Dspring.pid.file=./logs/application.pid -Dspring.pid.fail-on-write-error=true -jar /eureka/lib/eureka.jar';
  config:
    restart: always
    image: "semanteme/config:latest"
    hostname: config
    networks:
      - finance-net
    environment:
      - TZ=Asia/Shanghai
    ports:
      - "9093:9093"
  gateway:
    restart: always
    image: "semanteme/gateway:latest"
    hostname: gateway
    networks:
      - finance-net
    environment:
      - TZ=Asia/Shanghai
      - SLEEP_SECOND=4
    depends_on:
      - eureka
    ports:
      - "9092:9092"
    links:
      - eureka
    tty: true
    entrypoint: /entrypoint.sh -d eureka:9091 -c 'java -Djava.security.egd=file:/dev/./urandom -Dlogs.home=./logs -Dlogging.config=./config/logback-spring.xml -Dspring.config.location=file:./config/ -Dspring.pid.file=./logs/application.pid -Dspring.pid.fail-on-write-error=true -jar /gateway/lib/gateway.jar';
  cloud-agent-openstack:
    restart: always
    image: "semanteme/cloud-agent-openstack:latest"
    hostname: cloud-agent-openstack
    networks:
      - finance-net
    environment:
      - TZ=Asia/Shanghai
      - SLEEP_SECOND=4
    depends_on:
      - eureka
    ports:
      - "9095:9095"
    links:
      - eureka
    tty: true
    entrypoint: /entrypoint.sh -d gateway:9092 -c 'java -Djava.security.egd=file:/dev/./urandom -Dlogs.home=./logs -Dlogging.config=./config/logback-spring.xml -Dspring.config.location=file:./config/ -Dspring.pid.file=./logs/application.pid -Dspring.pid.fail-on-write-error=true -jar /cloud-agent-openstack/lib/cloud-agent-openstack.jar';
networks:
  finance-net:
    driver: bridge
  1. 使用compose文件部署
#启动所有服务
docker-compose up

#在后台所有启动服务
docker-compose up -d

#-f 指定使用的Compose模板文件,默认为docker-compose.yml,可以多次指定。
docker-compose -f docker-compose.yml up -d
问题总结问题
  1. idea无法连接docker, 提示需要输入email

原因与解决:idea版本问题,2019.2.4版本可用
在这里插入图片描述
2. 构建过程提示下列错误

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project eureka: Exception caught: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.docker.clie
nt.messages.RegistryAuth: no String-argument constructor/factory method to deserialize from String value ('desktop')
[ERROR]  at [Source: N/A; line: -1, column: -1] (through reference chain: java.util.LinkedHashMap["credsStore"])
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

原因与解决:插件版本导致,修改 1.0.0 为 0.4.13

<plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
<!--                <version>0.4.13</version>-->
                <version>1.0.0</version>
                <configuration>
                    <!--注意imageName一定要是符合正则[a-z0-9-_.]的,否则构建不会成功-->
                    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                    <!-- 指定了Dockfile的目录,所以需要在项目的src/main下创建一个docker目录,并在其目录中配置Dockerfile文件 -->
                    <dockerDirectory>${project.basedir}/docker</dockerDirectory>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.basedir}/dist</directory>
                            <include>eureka-release.tar</include>
                        </resource>
                    </resources>
                    <imageTags>
                        <imageTag>1.0.2</imageTag>
                        <imageTag>latest</imageTag>
                    </imageTags>
                </configuration>
            </plugin>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值