将写了几周的项目push 到阿里云的docker仓库。 并且记录下来,方便以后查阅。
1.在pom文件中增加plugin
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<docker.image.prefix>eroadsf</docker.image.prefix>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.3</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
2.增加src/main/docker/Dockerfile
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD spider-1.5.2.RELEASE.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
3.运行
mvn clean package docker:build
4. 打开命令行
docker images
5.登陆阿里云docker仓库
docker login --username [your username] registry.cn-hangzhou.aliyuncs.com/
docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/[仓库名称]/[命名空间]:[镜像版本号]
docker push registry.cn-hangzhou.aliyuncs.com/[仓库名称]/[命名空间]:[镜像版本号]
6.push成功了。
7.换台机器pull一下。
docker login --username [your username] registry.cn-hangzhou.aliyuncs.com/
docker pull registry.cn-hangzhou.aliyuncs.com/[仓库名称]/[命名空间]:[镜像版本号]
8.运行容器
docker run -d -p 18080:18080 [IMAGE ID ]
9.测试一下
curl http://localhost:18080/spider/