A, subject: stock of items so that items can be packaged codes unmodified mirror-image manner and any new items refer to the specification modification. Follow-up of new projects in development and testing environments are deployed using container deployment.
Second, the specific content: To the container of micro-services need to modify the pom.xml file and add src / main / dokcer / Dockerfile file.
Specific changes are as follows:
2.1. Pom.xml file modification
1. Add custom attribute image repository at <properties> path
<aliyun-sdk-oss.version>3.3.0</aliyun-sdk-oss.version> <docker.repostory>registry.cn-shenzhen.aliyuncs.com</docker.repostory> <docker.registry.name>xxxx_microservices</docker.registry.name>
2. Add package upload to the mirror disposed at the warehouse <build> </ build>
<!-- 使用maven 配置构建 --> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.0.0</version> <configuration> <dockerDirectory>target/docker</dockerDirectory> <imageName>${docker.repostory}/${docker.registry.name}/${project.artifactId}-${profileActive}</imageName> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> <serverId>docker-aliyun</serverId> <registryUrl>${docker.repostory}</registryUrl> <pushImage>true</pushImage> </configuration> </plugin>
3. Add the following arranged in <resources> </ resources>:
<!-- 使用@@站位符,输出Dockerfile至docker文件夹 --> <resource> <directory>src/main/docker</directory> <filtering>true</filtering> <includes> <include>**/Dockerfile</include> </includes> <targetPath>../docker</targetPath> </resource>
2.2. Adding Dockerfile file
Created under src / main directory new docker, Dockerfile new file in the directory, as follows:
ARG activenv FROM java:8-jre ENV arch @project.artifactId@ ENV prg @[email protected] ENV JAVA_OPTS="-Xms512m -Xmx512m" #ENV activenv="" EXPOSE 8084 RUN mkdir -p /vol1/appserver/$arch WORKDIR /vol1/appserver/$arch #VOLUME /vol1/logs ADD $prg . #设置时区 RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN sh -c echo 'Asia/Shanghai' >/etc/timezone #ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar"] ENTRYPOINT [ "sh", "-c", "java -Dfile.encoding=utf-8 $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar $prg > /dev/null 2>&1" ]
----------------------------------------------------------------------------------
Annex: packaged mirror command : tag will be marked to the mirror and pushed to the mirror provided inside the warehouse pom.xml
mvn clean package -P dev docker:build -DdockerImageTags=$JOB_NAME$BUILD_NUMBER