{"id":76,"date":"2023-08-28T01:01:48","date_gmt":"2023-08-28T08:01:48","guid":{"rendered":"https:\/\/eisaichen.com\/?p=76"},"modified":"2024-05-01T22:48:50","modified_gmt":"2024-05-02T05:48:50","slug":"how-to-run-windows-container-with-ultralight-docker-ce-cli","status":"publish","type":"post","link":"https:\/\/eisaichen.com\/?p=76","title":{"rendered":"How to run Windows Container with ultralight Docker-CE CLI"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><br><strong>This will NOT include the docker desktop, and it is COMMAND-LINE ONLY, Like in Linux.<\/strong><br>Hyper-V, WSL, VT-d are NOT required.<br>Please check <a href=\"#Limitations\" data-type=\"internal\" data-id=\"#Limitations\">Limitations<\/a> first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Install<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>You only need 4 files in total.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First download docker engine from the official:<br><a href=\"https:\/\/download.docker.com\/win\/static\/stable\/x86_64\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/download.docker.com\/win\/static\/stable\/x86_64\/<\/a><br>After unzipping, you will have the following 3 files:<br>docker.exe<br>dockerd.exe<br>docker-proxy.exe<br><br>Put all 3 files into whatever folder you want as the install folder, for example:<br>C:\\Program Files\\docker<br>Add the install folder to your environment variable (Optional)<br><code><kbd>PS(ADMIN)&gt;[Environment]::SetEnvironmentVariable('Path',\"$([Environment]::GetEnvironmentVariable('Path','Machine'))\"+';&lt;path to docker&gt;','Machine')<\/kbd><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then, download the docker-compose from the official repo: (Optional)<br><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/docker\/compose\/releases\/\" target=\"_blank\">https:\/\/github.com\/docker\/compose\/releases\/<\/a><br>you will get <code><kbd>docker-compose-windows-x86_64.exe<\/kbd><\/code><br>Rename it to <code><kbd>docker-compose.exe<\/kbd><\/code><br>Put it to C:\\Users\\&lt;username&gt;\\.docker\\cli-plugins<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run docker without Elevated privileges: (Optional)<br><code><kbd>PS(ADMIN)&gt;net localgroup docker \/add<\/kbd><br><kbd>PS(ADMIN)&gt;net localgroup docker &lt;your username&gt; \/add<\/kbd><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, register the docker service:<br>If you set up the group above<br><kbd>PS(ADMIN)&gt;&amp;'&lt;Path to docker&gt;\\dockerd.exe' --register-service -G docker<\/kbd><br>Otherwise<br><kbd>PS(ADMIN)&gt;&amp;'&lt;Path to docker&gt;\\dockerd.exe' --register-service<\/kbd><br><br>Final step, enable the <strong>Containers<\/strong> feature for Windows.<br>(optional) If you want to use <a href=\"#sp\" data-type=\"internal\" data-id=\"#sp\">hyper-v isolation<\/a> for your container, then you need to enable Hyper-V as well.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"415\" height=\"368\" src=\"https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/containerfeature.png\" alt=\"\" class=\"wp-image-81\" srcset=\"https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/containerfeature.png 415w, https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/containerfeature-300x266.png 300w\" sizes=\"auto, (max-width: 415px) 100vw, 415px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it, restart computer, and you are ready to go.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To verify the installation:<br><kbd>PS(ADMIN)&gt;docker version<\/kbd><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"676\" height=\"553\" src=\"https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-27-234020.png\" alt=\"\" class=\"wp-image-82\" srcset=\"https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-27-234020.png 676w, https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-27-234020-300x245.png 300w\" sizes=\"auto, (max-width: 676px) 100vw, 676px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Alternate Install<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Download the following zip and run the install.ps1 in PowerShell<\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-8db962ce-50d8-4468-9218-df888d13dae8\" href=\"https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/docker_install-1.zip\">docker_install<\/a><a href=\"https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/docker_install-1.zip\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-8db962ce-50d8-4468-9218-df888d13dae8\">Download<\/a><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This will automatically install docker into <kbd>C:\\Program Files\\docker<\/kbd><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Limitations\"><br>Limitations<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can only run Windows-based images. To run Linux-based image, you need Docker Desktop or WSL.<\/li>\n\n\n\n<li><strong>You can only run images that match your Windows build version<\/strong>, you can run <kbd>winver<\/kbd> to check your version.<br>Except Win11 can run version 20348 and above, therefore Win11 or Server2022 are recommended.<\/li>\n\n\n\n<li>Docker engine seems does not correctly clean temp data for Windows. You may need to clean it manually if space is needed.<br>Default path: <kbd>C:\\ProgramData\\docker<\/kbd><br>Take over ownership, assign yourself permissions then remove it.<\/li>\n\n\n\n<li>Windows images are huge, can easily take 10-100GB and more.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sp\"><br>Special features<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Those arguments are exclusive to Docker for Windows<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><kbd>--isolation &lt;hyperv | process><\/kbd>, for example:<br><kbd>Docker run -it --rm --isolation hyperv mcr.microsoft.com\/windows\/nanoserver:ltsc2022 cmd<\/kbd><br>There are two options <kbd>hyperv<\/kbd> or <kbd>process<\/kbd>. Both <code><kbd>docker run<\/kbd><\/code> and <code><kbd>docker build<\/kbd><\/code> can use this argument.<br>In short, process mode is the way you typically use in Linux, I suggest you <strong>run<\/strong> containers in this mode.<br>Hyperv mode means you will run the container inside a VM for full separation from the host. I suggest you <strong>build<\/strong> containers in this mode. This mode requires hyper-v installed on the host.<br><br><kbd>--cpu_count &lt;int><\/kbd><br>Specify how many cores you want to assign to the container.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Docker Hub Containers for Windows<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/hub.docker.com\/search?q=&amp;operating_system=windows\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/hub.docker.com\/search?q=&amp;operating_system=windows<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><br>Build Containers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Basically, there is no difference then the Linux version.<br>Here is an example of a container that run Stable-Diffusion with CUDA GPU support<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Dockerfile<\/h4>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"wp-block-code\"><code>FROM mcr.microsoft.com\/windows\/server:ltsc2022\n\nEXPOSE 7860\n\nENV SKIP_VENV=1\nENV VENV_DIR=-\nENV COMMANDLINE_ARGS='--update-check --listen --data-dir .\\\\udata'\n\nCOPY .\/res C:\/res\n\nWORKDIR C:\/res\n\nRUN powershell Start-Process -wait -FilePath python-3.10.11-amd64.exe -ArgumentList '\/quiet InstallAllUsers=0 InstallLauncherAllUsers=0 PrependPath=1' ; \\\n    Start-Process -wait -FilePath vc_redist.x64.exe -ArgumentList '\/install \/passive \/norestart' ; \\\n    Move-Item -Force '.\\git' 'C:\\Program Files\\' ; \\\n    Move-Item -Force '.\\nvdll\\*' 'C:\\Windows\\System32\\' ; \\\n    Start-Process -wait -FilePath regsvr32 -ArgumentList '\/s C:\\Windows\\System32\\nvcuda.dll' ; \\\n    Start-Process -wait -FilePath regsvr32 -ArgumentList '\/s C:\\Windows\\System32\\nvapi64.dll' ; \\\n    Import-Certificate -FilePath .\\cacert.sst -CertStoreLocation 'Cert:\\LocalMachine\\Root' ; \\\n    &#91;Environment]::SetEnvironmentVariable('Path',\"$(&#91;Environment]::GetEnvironmentVariable('Path','Machine'))\"+';C:\\Program Files\\git\\bin','Machine')\n\nWORKDIR C:\/\nRUN git clone https:\/\/github.com\/AUTOMATIC1111\/stable-diffusion-webui.git .\\app &amp;&amp; \\\n    git config --global --add safe.directory \"*\" &amp;&amp; \\\n    cd .\\app &amp;&amp; \\\n    rmdir \/s \/q c:\\res &amp;&amp; \\\n    pip install --no-cache-dir torch --index-url https:\/\/download.pytorch.org\/whl\/cu118 &amp;&amp; \\\n    pip install --use-pep517 --no-cache-dir -r requirements.txt --prefer-binary &amp;&amp; \\\n    set COMMANDLINE_ARGS=--exit --xformers --skip-torch-cuda-test &amp;&amp; \\\n    pip cache purge &amp;&amp; \\\n    webui.bat\n\n\nWORKDIR C:\/app\nCMD webui.bat<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">docker-compose.yaml<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>version: \"3.8\"\n\nnetworks:\n  windows:\n\nservices:\n  windows:\n    container_name: stable_diffusion\n    build:\n      context: .\\build\n      isolation: hyperv     # Change this to \"process\" if you dont have hyperv\n      no_cache: true\n    isolation: process\n    networks:\n      - stable_diffusion\n    cpu_count: 8\n    ports:\n      - \"7860:7860\"\n    environment:\n      - COMMANDLINE_ARGS=--update-check --listen --data-dir .\\\\udata --medvram     # See https:\/\/github.com\/AUTOMATIC1111\/stable-diffusion-webui\/wiki\/Command-Line-Arguments-and-Settings\n    volumes:\n      - '.\\data:C:\\app\\udata'\n      - '.\\outputs:C:\\app\\outputs'\n    devices:\n      - class\/5B45201D-F2F2-4F3B-85BB-30FF1F953599     # Passing GPU, This GUID is fixed\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Resources<\/h4>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"380\" height=\"233\" src=\"https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/Untitled2.png\" alt=\"\" class=\"wp-image-90\" srcset=\"https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/Untitled2.png 380w, https:\/\/eisaichen.com\/wp-content\/uploads\/2023\/08\/Untitled2-300x184.png 300w\" sizes=\"auto, (max-width: 380px) 100vw, 380px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">References<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/learn.microsoft.com\/en-us\/virtualization\/windowscontainers\/manage-docker\/manage-windows-dockerfile\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/learn.microsoft.com\/en-us\/virtualization\/windowscontainers\/manage-docker\/manage-windows-dockerfile<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This will NOT include the docker desktop, and it is COMMAND-LINE ONLY, Like in Linux.Hyper-V, WSL, VT-d are NOT required.Please check Limitations first. Install You only need 4 files in total. First download docker engine from the official:https:\/\/download.docker.com\/win\/static\/stable\/x86_64\/After unzipping, you will have the following 3 files:docker.exedockerd.exedocker-proxy.exe Put all 3 files into whatever folder you want [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":78,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-76","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/eisaichen.com\/index.php?rest_route=\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eisaichen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eisaichen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eisaichen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eisaichen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=76"}],"version-history":[{"count":25,"href":"https:\/\/eisaichen.com\/index.php?rest_route=\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/eisaichen.com\/index.php?rest_route=\/wp\/v2\/posts\/76\/revisions\/148"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eisaichen.com\/index.php?rest_route=\/wp\/v2\/media\/78"}],"wp:attachment":[{"href":"https:\/\/eisaichen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eisaichen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eisaichen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}