网站首页 > 开源技术 正文
window系统的家庭版无法安装Docker Desktop,网上很多的解决方案大多建议更改window的版本为专业或者商业的版本,或者是使用主流的虚拟机,再在里面嵌套docker。其实还有一个比较简单的办法,就是使用window内置的wsl(适用于windows的Linux子系统)功能。然后再在其子系统中安装docker,wsl子系统的好处是可以硬件直通。
关于windows如何开启WSL子系统,可以参考这篇文章:win10或11安装wsl开启适用于windows的Linux子系统
一、拉取ubuntu子系统
先查看在线支持的子系统有那些
PS C:\Windows\system32> wsl --list --online
以下是可安装的有效分发的列表。
使用 'wsl.exe --install <Distro>' 安装。
NAME FRIENDLY NAME
Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
Ubuntu-18.04 Ubuntu 18.04 LTS
Ubuntu-20.04 Ubuntu 20.04 LTS
Ubuntu-22.04 Ubuntu 22.04 LTS
Ubuntu-24.04 Ubuntu 24.04 LTS
OracleLinux_7_9 Oracle Linux 7.9
OracleLinux_8_7 Oracle Linux 8.7
OracleLinux_9_1 Oracle Linux 9.1
openSUSE-Leap-15.6 openSUSE Leap 15.6
SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5
SUSE-Linux-Enterprise-15-SP6 SUSE Linux Enterprise 15 SP6
openSUSE-Tumbleweed openSUSE Tumbleweed
可以看到,支持的子系统不少,这里演示拉取最新的ubuntu2404LTS版本,使用命令wsl --install <子系统名>来安装子系统,子系统名使用的是上面wsl --list --online中列出的NAME。安装完成后,根据提示输入一个ubuntu的用户名,以及输入密码和确认输入密码后,就可以看见熟悉的linux命令行提示符,用户名是你刚才输入的用户名,主机名则是你Windows的主机名。
PS C:\Windows\system32> wsl --install ubuntu-24.04
正在安装: Ubuntu 24.04 LTS
已安装 Ubuntu 24.04 LTS。
正在启动 Ubuntu 24.04 LTS...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: sean
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
Welcome to Ubuntu 24.04 LTS (GNU/Linux 5.15.153.1-microsoft-standard-WSL2 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Wed Aug 28 23:22:42 CST 2024
System load: 1.31 Processes: 35
Usage of /: 0.1% of 1006.85GB Users logged in: 0
Memory usage: 20% IPv4 address for eth0: 172.27.66.213
Swap usage: 0%
This message is shown once a day. To disable it please create the
/home/sean/.hushlogin file.
sean@vmpc:~$
二、子系统中安装docker
上面的步骤为安装子系统时自动进入子系统的命令行,那么如何运行打开一个子系统呢?
首先打开PowerShell窗口,点击当前标签旁边的下拉菜单按键,下拉菜单中有我们当前已经安装的子系统名称,点击名称即可进入到对应的子系统中去。
进入系统后,直接使用apt包管理命令安装docker.io就可以了,需要注意的是,在debian一系的apt软件仓库中,docker这个名字是指向另外一个软件,咱们要用的docker-ce的包名字是docker.io。
sudo apt install docker.io
查看docker的版本,确定docker已经安装完成
sean@vmpc:~$ sudo docker version
Client:
Version: 24.0.7
API version: 1.43
Go version: go1.22.2
Git commit: 24.0.7-0ubuntu4.1
Built: Fri Aug 9 02:33:20 2024
OS/Arch: linux/amd64
Context: default
Server:
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.22.2
Git commit: 24.0.7-0ubuntu4.1
Built: Fri Aug 9 02:33:20 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.12
GitCommit:
runc:
Version: 1.1.12-0ubuntu3.1
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
三、配置docker并使用
1、docker安装完成后,如果不想每次在输入命令前都要加上sudo的话,运行下面的命令
sudo usermod -aG docker $USER && newgrp docker
2、配置国内仓库源或自己的私有仓库源,在/etc/docker/daemon.json文件中添加以下的内容即可。配置完成后需要重启docker的服务sudo systemctl restart docker方可生效。
"registry-mirrors": [
"https://国内可用仓库的域名",
"https://私有仓库的IP:端口"
]
3、配置docker在子系统启动的时候跟着自启动
sudo systemctl enable docker
四、拉取镜像并测试运行容器
拉取一个容量比较小的镜像,测试一下是否可以正常拉取镜像,
sean@vmpc:~$ docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
43c4264eed91: Pull complete
Digest: sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
sean@vmpc:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 91ef0af61f39 3 weeks ago 7.8MB
利用这个镜像创建一个容器
sean@vmpc:~$ docker run -it --name hello alpine:latest echo "hello world"
hello world
sean@vmpc:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e1eabd6e985 alpine:latest "echo 'hello world'" 10 seconds ago Exited (0) 7 seconds ago
hello
如果以上都可以正常运行,恭喜你,你已经可以在家庭版的window下面使用docker了。而且是显卡直通的那种。
猜你喜欢
- 2024-10-27 什么是容器运行时?(什么是 容器)
- 2024-10-27 震惊!八岁儿子竟知道容器测评十个小知识?老爸,他开天眼了?
- 2024-10-27 红帽RHEL8和RHEL7有什么区别?(红帽8和红帽7区别大不大)
- 2024-10-27 Docker基础简介(docker通俗易懂)
- 2024-10-27 Linux命令笔记-01(linux命令教程)
- 2024-10-27 runc_page allocation failure排查
- 2024-10-27 Nvidia GPU如何在Kubernetes 里工作
- 2024-10-27 容器运行时分类(容器的运行实例)
- 2024-10-27 重学容器02: 部署容器运行时Containerd
- 2024-10-27 什么是runwasi(什么是润物细无声的教育)
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- jdk (81)
- putty (66)
- rufus (78)
- 内网穿透 (89)
- okhttp (70)
- powertoys (74)
- windowsterminal (81)
- netcat (65)
- ghostscript (65)
- veracrypt (65)
- asp.netcore (70)
- wrk (67)
- aspose.words (80)
- itk (80)
- ajaxfileupload.js (66)
- sqlhelper (67)
- express.js (67)
- phpmailer (67)
- xjar (70)
- redisclient (78)
- wakeonlan (66)
- tinygo (85)
- startbbs (72)
- webftp (82)
- vsvim (79)
本文暂时没有评论,来添加一个吧(●'◡'●)