WIN11-23H2专业版+WSL2搭建docker-compose服务总结

前置条件

window11系统安装+激活

1,通过winpe进行系统安装,安装系统后无法通过硬盘启动的话需要重新进行下分区,用分区精灵选择快速分区,选择GUID分区(ThinkPad 通过F1进入bios设置)
2,安装不带三方软件的系统
1)下载iso原生镜像,通过winpe进行安装
2) 在pe系统里面右键原生镜像进行挂载
3)选择挂载后的磁盘里面instsll.esd进行安装,这样安装的系统不会带预装软件
3,建议购买正版激活码进行激活 windows+office

wsl2安装

1,初始化安装:右键单击并选择“以管理员身份运行”,输入 wsl --install 命令,然后重启计算机
2,在powershell列出可以用的wsl2版本:wsl -l -o
3,若要初始化安装后安装其他版本,可以执行wsl --install -d <Distribution Name>
4,安装之后输入linux的账号密码

wsl2基本配置

1,配置镜像网络:
1) 打开PScd ~
2) 新建.wslconfig 并且在文件键入如下内容:

[wsl2]
networkingMode=mirrored

2,对wsl2子系统进行迁移及恢复
1)
wsl -l -v查看所有安装的wsl子系统
2)
wsl --export {NAME} {Customized Name}.tar对进行进行备份
3)
wsl --import {New WSL Name} {New WSL Save Path} {Customized Name}.tar对备份的wsl进行恢复
4)
这时候wsl -l -v就会看见新的WSL镜像,进行运行即可,所有关于这个镜像的文件都会存在{New WSL Save Path}

3,如果在wsl2里面搭建了docker服务但是无法通过http://localhost:port访问的话需要在wsl里面进行配置:

sudo vim /etc/docker/daemon.json
{
  "iptables": false
}

4,然后重启docker服务

sudo service docker restart

wsl2安装docker&docker-compose步骤

安装Dokcer

curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
sudo usermod -aG	docker ${USER}

检测docker是否安装完成

docker version

如果最后一行报错“Cannot connect to Docker daemon at xxxx”
说明是docker-engine 没起来
需要执行

sudo service docker start 

执行如下行,让每次启动wsl时候会自动启动docker-engine

sudo systemctl enable  docker

安装docker-compose

1,下载Docker Compose的可执行文件。可以使用以下命令下载最新版本:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

下载缓慢可以使用国内代理服务下载:

sudo curl -L "https://ghproxy.com/https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

如果要安装特定版本的Docker Compose,请将上述命令中的latest替换为所需的版本号。
2,赋予可执行权限给下载的二进制文件:

sudo chmod +x /usr/local/bin/docker-compose

3,创建一个符号链接,将docker-compose命令链接到/usr/bin目录,以便可以全局访问:

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

4,检验是否安装成功

docker-compose --version

补充:
迁移后默认的用户是root,如果想要更改默认的用户需要修改/etc/wsl.conf

[boot]
systemd=true
[user]
default = xxx

追加get-docker.sh

#!/bin/sh
set -e
# Docker Engine for Linux installation script.
#
# This script is intended as a convenient way to configure docker's package
# repositories and to install Docker Engine, This script is not recommended
# for production environments. Before running this script, make yourself familiar
# with potential risks and limitations, and refer to the installation manual
# at https://docs.docker.com/engine/install/ for alternative installation methods.
#
# The script:
#
# - Requires `root` or `sudo` privileges to run.
# - Attempts to detect your Linux distribution and version and configure your
#   package management system for you.
# - Doesn't allow you to customize most installation parameters.
# - Installs dependencies and recommendations without asking for confirmation.
# - Installs the latest stable release (by default) of Docker CLI, Docker Engine,
#   Docker Buildx, Docker Compose, containerd, and runc. When using this script
#   to provision a machine, this may result in unexpected major version upgrades
#   of these packages. Always test upgrades in a test environment before
#   deploying to your production systems.
# - Isn't designed to upgrade an existing Docker installation. When using the
#   script to update an existing installation, dependencies may not be updated
#   to the expected version, resulting in outdated versions.
#
# Source code is available at https://github.com/docker/docker-install/
#
# Usage
# ==============================================================================
#
# To install the latest stable versions of Docker CLI, Docker Engine, and their
# dependencies:
#
# 1. download the script
#
#   $ curl -fsSL https://get.docker.com -o install-docker.sh
#
# 2. verify the script's content
#
#   $ cat install-docker.sh
#
# 3. run the script with --dry-run to verify the steps it executes
#
#   $ sh install-docker.sh --dry-run
#
# 4. run the script either as root, or using sudo to perform the installation.
#
#   $ sudo sh install-docker.sh
#
# Command-line options
# ==============================================================================
#
# --version <VERSION>
# Use the --version option to install a specific version, for example:
#
#   $ sudo sh install-docker.sh --version 23.0
#
# --channel <stable|test>
#
# Use the --channel option to install from an alternative installation channel.
# The following example installs the latest 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值