IDEA部署Docker到WSL2的详细过程

时间:2022-06-04 03:46:16

本地环境 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内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

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