目录
一、创建文件Dockerfile,内容如下:
FROM java:8 MAINTAINER demo@test.io ENV MYPATH /root WORKDIR $MYPATH VOLUME $MYPATH ARG JAR_FILE=*.jar COPY ${JAR_FILE} boot-demo.jar RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN echo 'Asia/Shanghai' >/etc/timezone EXPOSE 8090 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","boot-demo.jar"]
二、构建镜像。
docker build -t boot-demo .
三、启动运行
sudo docker run -itd --name boot-demo --privileged --restart=unless-stopped -p 8090:8090 boot-demo:latest
四、推送到docker hub
4.1 登录docker hub
docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: 你的用户名
Password: 你的密码
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
You have new mail in /var/spool/mail/root
4.2 tag
docker tag boot-demo:latest zhxl1989/boot-demo:latest
4.3 docker push
docker push zhxl1989/boot-demo:latest