目录
待用文件提取
- 构建镜像semanteme/openjdk8u181:0.0.1文件提取
链接:https://pan.baidu.com/s/1rmjgU1AYhv5zoflY4foLQw
提取码:4iy3
- pom文件提取
链接:https://pan.baidu.com/s/1ntamSPKZxPgsYgw6T5ORPw
提取码:9y0w
- dockerfile文件提取
链接:https://pan.baidu.com/s/1sJ9joKih148c6gW8EjFvwg
提取码:4c2q
- compose文件提取
链接:https://pan.baidu.com/s/1r6cTru-XniIYgsQaxXrT0Q
提取码:gvgv
一:idea连接docker配置
- 修改配置文件,打开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文件
- 编写镜像部署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镜像并部署
- idea构建服务包,根据dockerfile文件配置,服务包应与dockerfile在同一目录下
- Edit Configurations配置构建与部署参数
- 点击运行,构建镜像并部署
maven构建docker镜像并使用compose文件部署
- 配置添加镜像构建的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环境变量
此处需设置正确的配置参数
- 使用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
- 使用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
- 使用compose文件部署
#启动所有服务
docker-compose up
#在后台所有启动服务
docker-compose up -d
#-f 指定使用的Compose模板文件,默认为docker-compose.yml,可以多次指定。
docker-compose -f docker-compose.yml up -d
问题总结问题
- 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>