标签:package dom use java des user org config ror
docker:容器化管理
maven:支持docker-maven的插件,通过 mvn clean -Dmaven.test.skip package dockerfile:build 打包命令和配置 Dockerfile 直接打出 docker 镜像
docker-compose:服务端容器编排,使得多个容器可进行批量发布等管理操作
<properties>
<java.version>1.8</java.version>
<guava.version>20.0</guava.version>
<dockerfile-maven-plugin.version>1.3.6</dockerfile-maven-plugin.version>
<docker-client.version>8.10.1</docker-client.version>
<!-- Docker镜像仓库 -->
<docker.registry>xxxx</docker.registry>
<docker.namespace>xxx</docker.namespace>
<docker.repo>xx</docker.repo>
<java.lib>${project.basedir}/src/main/resources/lib</java.lib>
</properties>
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--开启本地引入JAR包--> <configuration> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> <plugin>
<!-- 这里引入dockerfile-maven插件 --> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>${dockerfile-maven-plugin.version}</version> <dependencies> <dependency> <groupId>com.spotify</groupId> <artifactId>docker-client</artifactId> <version>${docker-client.version}</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>${guava.version}</version> </dependency> </dependencies> <configuration> <tag>${project.artifactId}-latest</tag> <repository>${docker.registry}/${docker.namespace}/${docker.repo}</repository> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin> </plugins> </build>
在pom.xml同级目录下编写Dockerfile
FROM java:8 VOLUME /tmp ARG JAR_FILE ADD ${JAR_FILE} app.jar ENTRYPOINT ["java","-Xmx192m", "-XX:+UseConcMarkSweepGC", "-Djava.security.egd=file:/dev/./urandom","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=/mnt/logs/heapdump_test.hprof","-jar","/test-1.0.0.RELEASE.jar"]
mvn clean -Dmaven.test.skip package dockerfile:build
docker login --username=root registry.cn-xxx.aliyuncs.com docker tag [镜像ID] registry.cn-xxx.aliyuncs.com/namespace/repo: [镜像版本号] docker push registry.cn-chengdu.aliyuncs.com/kidcloud/kidcloud_repo: [镜像版本号]
curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose docker-compose –version
version: ‘1‘ services: demo: image: ${私服地址}/${命名空间}/${仓库名}:${镜像名称版本号} environment: - server.port=9001 - eureka.client.serviceUrl.defaultZone=http://discovery:8761/eureka/ - JAVA_OPTS=‘-Xmx512m -Xms512m‘ ports: - "9001:9001" networks: - demoNetwork volumes: - /mnt/logs:/mnt/logs external_links: - eureka-server:discovery networks: demoNetwork: external: true
docker-compose -f xxx.yaml up -d
docker-compose up -d
更多docker-compose命令:
Docker + Maven + Docker-compose
标签:package dom use java des user org config ror
原文地址:https://www.cnblogs.com/lcmlyj/p/12120089.html