一、docker-windows介绍

虽然说电脑可以实现双系统,但是有时候啊,像一些堡垒机或者vpn啥的,或者需要windows环境做测试的,你总不能老是切换系统吧,很麻烦,而且用习惯了linux,总是想鼓捣着可以用ubuntu搞定万物,反正有docker嘛,万物皆可docker,于是今天我查了一下资料,找到了docker镜像的windows,这样工作起来就方便多了。

二、本次实践介绍

  1. 本次实践简介

本次实践部署环境为个人测试环境

  1. 本地环境规划

本次实践环境规划:下载镜像dockurr/windows:latest,通过docker-cli或者docker compose启动容器

镜像命名

IP地址

容器镜像版本

操作系统版本

windows

localhost

latest

ubuntu 22.04

三、检查本地Docker环境

  1. 检查本地Docker版本
检查Docker版本:docker version

root@WellDone:/home/goodjob# docker version
Client: Docker Engine - Community
 Version:           25.0.0
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        e758fe5
 Built:             Thu Jan 18 17:09:49 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.0
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       615dfdf
  Built:            Thu Jan 18 17:09:49 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.27
  GitCommit:        a1496014c916f9e62104b33d1bb5bd03b0858e59
 runc:
  Version:          1.1.11
  GitCommit:        v1.1.11-0-g4bccb38
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
root@WellDone:/home/goodjob#
  1. 检查Docker服务状态

检查Docker服务状态,确保Docker服务正常运行。

systemctl status docker

root@WellDone:/home/goodjob/Downloads# systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-01-24 08:54:31 CST; 1 day 4h ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 1549 (dockerd)
      Tasks: 65
     Memory: 419.5M
        CPU: 38.874s
     CGroup: /system.slice/docker.service
             ├─  1549 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
             ├─  2010 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 6379 -container-ip 172.17.0.2 -container-port 6379
             ├─  2016 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 6379 -container-ip 172.17.0.2 -container-port 6379
             ├─  2029 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5432 -container-ip 172.17.0.3 -container-port 5432
             ├─  2036 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5432 -container-ip 172.17.0.3 -container-port 5432
             ├─123083 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8888 -container-ip 172.17.0.4 -container-port 8080
             └─123095 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8888 -container-ip 172.17.0.4 -container-port 8080

1月 24 08:54:31 WellDone dockerd[1549]: time="2024-01-24T08:54:31.067895045+08:00" level=info msg="API listen on /run/docker.sock"
1月 24 08:54:31 WellDone systemd[1]: Started Docker Application Container Engine.
1月 24 16:13:48 WellDone dockerd[1549]: time="2024-01-24T16:13:48.185008219+08:00" level=info msg="ignoring event" container=8ad99af82d8a41dd661d>
1月 24 16:13:48 WellDone dockerd[1549]: time="2024-01-24T16:13:48.189484205+08:00" level=warning msg="ShouldRestart failed, container will not be>
1月 24 21:58:08 WellDone dockerd[1549]: time="2024-01-24T21:58:08.024915139+08:00" level=info msg="ignoring event" container=27fd28e2993f31b170b8>
1月 24 21:58:08 WellDone dockerd[1549]: time="2024-01-24T21:58:08.029986730+08:00" level=warning msg="ShouldRestart failed, container will not be>
1月 25 10:46:16 WellDone dockerd[1549]: time="2024-01-25T10:46:16.329180722+08:00" level=info msg="Container failed to exit within 10s of signal >
1月 25 10:46:16 WellDone dockerd[1549]: time="2024-01-25T10:46:16.350757439+08:00" level=info msg="ignoring event" container=b1223add00f36bbb3246>
1月 25 10:49:21 WellDone dockerd[1549]: time="2024-01-25T10:49:21.993755983+08:00" level=info msg="Container failed to exit within 10s of signal >
1月 25 10:49:22 WellDone dockerd[1549]: time="2024-01-25T10:49:22.015822650+08:00" level=info msg="ignoring event" container=edb0e153b45dbe62acd8>
lines 1-28/28 (END)

四、部署windows镜像

  1. 下载windows镜像
docker pull dockurr/windows:latest
  1. 创建容器

使用docker快速创建windows的容器。

完整创建过程:

1.使用docker-cli启动一个windows的容器。

--VERSION决定你启动容器后下载的系统是什么;
--RAM_SIZE决定你给这个系统的运存是多少;
--CPU_CORES决定你给这个系统的cpu是多少;
--DISK_SIZE决定了你给这个系统的磁盘大小是多少;
--/opt/windows/storage:/storage这里的是你挂载的目录;
--其他的可以按照我的参数设置即可
 
docker run -it \
-e VERSION="win10" \
-e RAM_SIZE="8G" \
-e CPU_CORES="4" \
-e DISK_SIZE="50G" \
-e MANUAL="N" \
-p 8006:8006 \
-p 3389:3389/tcp \
-p 3389:3389/udp \
-v /usrlocal/docker-win/win:/storage \
--device=/dev/kvm \
--cap-add NET_ADMIN \ 
dockurr/windows:latest\

2.使用docker-compose启动一个windows的容器

version: "3"
services:
  windows:
    image: dockurr/windows:latest
    container_name: windows
    stop_grace_period: 2m
    restart: unless-stopped
    environment:
      VERSION: "win10"
      RAM_SIZE: "8G"
      CPU_CORES: "4"
      DISK_SIZE: "50G"
      MANUAL: "N"
    devices:
      - /dev/kvm
    cap_add:
      - NET_ADMIN
    ports:
      - 8006:8006
      - 3389:3389/tcp
      - 3389:3389/udp
    volumes:
      - /use/local/docker-win/win:/storage



3.容器启动正常,访问
http://ip:8006

3. 检查容器运行状态

检查容器的运行状态,确保服务的正常运行。

docker ps

root@WellDone:/home/goodjob# docker ps
CONTAINER ID   IMAGE                                                       COMMAND                   CREATED         STATUS         PORTS                                       NAMES
1323a8db41c5   dockurr/windows:latest                                             "/usr/bin/tini -s /r…"   23 hours ago   Up 39 minutes           0.0.0.0:3389->3389/tcp, :::3389->3389/tcp, 0.0.0.0:8006->8006/tcp, 0.0.0.0:3389->3389/udp, :::8006->8006/tcp, :::3389->3389/udp   windows

五、访问windows页面

访问photopea首页 访问地址:http://localhost:8006

【打工日常】使用docker部署在线windows_Docker