main目录下添加Dockerfile
TIM截图20180813084350.jpg
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD amy-1.0.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" ]
参数说明
amy-1.0.jar jar包名字
添加maven docker插件
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<!--<version>0.2.3</version>-->
<version>0.4.11</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>
制作镜像
$ docker build -t amyservice .
-t代表要构建的镜像的tag
.代表当前目录,也就是Dockerfile所在的目录
启动
$ docker run -d -p 8086:8086 --name amy amyservice:latest
进入容器,alpine为精简版本linux 没有安装bash shell,需要用ash
$ docker exec -it ID ash
网友评论