docker配置运行远程访问
1、配置docker远程连接端口
vi /usr/lib/systemd/system/docker.service
2、找到 ExecStart,在最后面添加 -H tcp://0.0.0.0:2375
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375 ##这里添加
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
3、重启docker
systemctl daemon-reload && systemctl start docker
4、开放端口和防火墙
firewall-cmd --zone=public --add-port=2375/tcp --permanent
iptables -I INPUT -p tcp --dport 2375 -j ACCEPT
5、验证
curl http://192.168.111.201:2375/version
{"Platform":{"Name":"Docker Engine - Community"},"Components":[{"Name":"Engine","Version":"19.03.13","Details":{"ApiVersion":"1.40","Arch":"amd64","BuildTime":"2020-09-16T17:02:21.000000000+00:00","Experimental":"false","GitCommit":"4484c46d9d","GoVersion":"go1.13.15","KernelVersion":"3.10.0-1127.el7.x86_64","MinAPIVersion":"1.12","Os":"linux"}},{"Name":"containerd","Version":"1.3.7","Details":{"GitCommit":"8fba4e9a7d01810a393d5d25a3621dc101981175"}},{"Name":"runc","Version":"1.0.0-rc10","Details":{"GitCommit":"dc9208a3303feef5b3839f4323d9beb36df0a9dd"}},{"Name":"docker-init","Version":"0.18.0","Details":{"GitCommit":"fec3683"}}],"Version":"19.03.13","ApiVersion":"1.40","MinAPIVersion":"1.12","GitCommit":"4484c46d9d","GoVersion":"go1.13.15","Os":"linux","Arch":"amd64","KernelVersion":"3.10.0-1127.el7.x86_64","BuildTime":"2020-09-16T17:02:21.000000000+00:00"}
IDEA远程访问
1、安装docker插件并重启
File->Settings->Plugins->Marketplace->搜索docker->Docker安装
2、配置连接远程docker
windows如果无法远程连接Docker(可略)
检查上一步配置远程连接是否成功,接着看下虚拟机是否有问题,下面各项需要全部打开
3、配置docker远程仓库
4、创建一个Dockerfile配置
5、打包镜像
这一步之前需要先将打个jar包,存放到dockerfile中指定的位置,可以在Run Maven Goal中执行先打jar包
clean package -U -DskipTests
Dockerfile示例
FROM openjdk:8-jdk
VOLUME /tmp
ARG JAR_FILE
COPY target/${JAR_FILE} app.jar
RUN apt-get install -y tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& dpkg-reconfigure -f noninteractive tzdata
ENTRYPOINT exec java $JAVA_OPTS $JASYPT_OPS -Djava.security.egd=file:/dev/./urandom -jar /app.jar