IDEA部署Docker到WSL2的详细过程

2025-05-27 0 36

本地环境 windows10+wsl2(ubuntu),需要大家在服务器安装 docker 之后,开启远程访问

sudo vi /etc/default/docker 修改配置

?

1

2

3
# 开启远程访问 -h tcp://0.0.0.0:2375

# 开启本地套接字访问 -h unix:///var/run/docker.sock

docker_opts="-h tcp://0.0.0.0:2375 -h unix:///var/run/docker.sock"

sudo service docker restart 重启

idea 安装 docker 插件后,设置填写地址 tcp://192.168.50.28:2375 (自己的本机 ip 地址),成功连接的话有 connection successful 提示

IDEA部署Docker到WSL2的详细过程

tools 选项配置,需要先安装 windows 版本 docker,装完把程序关掉,开机自启关掉,因为我不想多开一个程序,ubuntu 里已经有 docker 了,这里只是要用到 docker-compose.exe 在 windows 环境做下容器编排而已。docker machine 用不着的话不用管。

IDEA部署Docker到WSL2的详细过程

一般的 dockerfile 文件和 docker-compose.yml 文件参考

?

1

2

3

4

5

6

7

8

9
from ubuntu:latest

copy target/*.jar /app.jar

env java_home="/usr/lib/jdk1.8"

env path="${path}:${java_home}/bin:${java_home}/sbin"

entrypoint [ "java", "-jar", "/app.jar" ]
?

1

2

3

4

5

6

7

8

9

10

11

12

13
version: '3'

services:

last:

build:

context: .

dockerfile: dockerfile

ports:

- "18080:8080"

volumes:

- /usr/lib/jvm/java-8-openjdk-amd64:/usr/lib/jdk1.8 #宿主机 jdk 映射给容器使用

tty: true

network_mode: bridge

restart: always

使用 docker-compose 创建 docker 容器

IDEA部署Docker到WSL2的详细过程

compose files 选择刚创建的 docker-compose.yml 文件

运行

deploying 'compose: lin-test'…
"c:\\program files\\docker\\docker\\resources\\bin\\docker-compose.exe" -f d:\\project\\gitfile\\lin\\lin-test\\docker-compose.yml up -d
building last
sending build context to docker daemon 61.72mb
step 1/5 : from ubuntu:latest
—> c29284518f49
step 2/5 : copy target/*.jar /app.jar
—> f13f1a3f4a0d
step 3/5 : env java_home="/usr/lib/jdk1.8"
—> running in ea05d01bf802
removing intermediate container ea05d01bf802
—> 9bb4f1a6be38
step 4/5 : env path="${path}:${java_home}/bin:${java_home}/sbin"
—> running in 73ab542794a5
removing intermediate container 73ab542794a5
—> a6d791e7bd7c
step 5/5 : entrypoint [ "java", "-jar", "/app.jar" ]
—> running in e1704a59d50b
removing intermediate container e1704a59d50b
—> 8ee7a6f5b53a
successfully built 8ee7a6f5b53a
successfully tagged lin-test_last:latest
security warning: you are building a docker image from windows against a non-windows docker host. all files and directories added to build context will have '-rwxr-xr-x' permissions. it is recommended to double check and reset permissions for sensitive files and directories.

use 'docker scan' to run snyk tests against images to find vulnerabilities and learn how to fix them
image for service last was built because it did not already exist. to rebuild this image you must use `docker-compose build` or `docker-compose up –build`.
creating lin-test_last_1 …
creating lin-test_last_1 … done
'compose: lin-test' has been deployed successfully.

到此这篇关于idea 部署 docker 到 wsl2的文章就介绍到这了,更多相关idea 部署 docker wsl2内容请搜索快网idc以前的文章或继续浏览下面的相关文章希望大家以后多多支持快网idc!

原文链接:https://blog.csdn.net/u012809062/article/details/118893098

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 行业资讯 IDEA部署Docker到WSL2的详细过程 https://www.kuaiidc.com/63896.html

相关文章

发表评论
暂无评论