1、创建Dockerfile
FROM java:8
MAINTAINER "Paulson <paulson@gmail.com>"
VOLUME /tmp
COPY target/spring-security-0.0.1-SNAPSHOT.jar security1.jar
EXPOSE 8082
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom","-jar","/security1.jar"]
2、构建镜像 docker build -t security .
3、运行
docker run -d --rm --name=security -p 8081:8081 security
4、查看docker 日志
docker logs -f --tail=500
5、开启端口
firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --reload 重启防火墙
systemctl stop firewalld.service 关闭防火墙
systemctl disable firewalld.service 禁止开机启动firewall
6、IDEA 整合
-
开启docker远程访问
修改宿主机上的docker配置文件,默认安装路径是/lib/systemd/system/docker.service
# 修改ExecStart
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
# 修改为:
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
# 重新加载docker配置文件
systemctl daemon-reload
# 重新启动docker服务
systemctl restart docker.service
# 查看端口是否开启
netstat -nlpt # 如果找不到netstat 。yum install net-tools
# 直接curl看是否生效
curl http://127.0.0.1:2375/info
-
IDEA 下载docker 插件 2019版本已经集成
配置docker镜像地址
![](https://img-blog.csdnimg.cn/20200304235257368.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM4NTM0MTA3,size_16,color_FFFFFF,t_70)
配置镜像加速器
在项目根目录下创建 Dockerfile 文件,右键
![](https://img-blog.csdnimg.cn/20200304235257370.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM4NTM0MTA3,size_16,color_FFFFFF,t_70)
配置
端口即可
![](https://img-blog.csdnimg.cn/20200304235257380.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM4NTM0MTA3,size_16,color_FFFFFF,t_70)
执行
![](https://img-blog.csdnimg.cn/20200304235257377.png)
![](https://img-blog.csdnimg.cn/20200304235257397.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM4NTM0MTA3,size_16,color_FFFFFF,t_70)