{"id":5118,"date":"2021-12-25T18:56:35","date_gmt":"2021-12-25T10:56:35","guid":{"rendered":"https:\/\/dmesg.app\/?p=5118"},"modified":"2021-12-26T11:54:41","modified_gmt":"2021-12-26T03:54:41","slug":"docker-windows-container","status":"publish","type":"post","link":"https:\/\/dmesg.app\/docker-windows-container.html","title":{"rendered":"\u4f7f\u7528Docker\u8dd1Windows\uff01"},"content":{"rendered":"<p><span style=\"font-size: 14pt;\"><strong>\u672c\u7cbe\u795e\u75c5\u4eba\u53c8\u6765\u95f9\u5996\u5566\uff01<\/strong><\/span><\/p>\n<hr \/>\n<p>\u81ea\u4ece\u6709\u4e86\u8fd9\u79cd\u5bb9\u5668\u5316\u6280\u672f\u4e4b\u540e\uff0c\u60f3\u8981\u505a\u6d4b\u8bd5\uff0c\u6784\u5efa\u70b9\u4ec0\u4e48\uff0c\u6216\u8005\u7b80\u5355\u7684\u4f53\u9a8c\u4e0b\u67d0\u4e2aLinux Distros\u7684cli\u5c31\u53d8\u7684\u65e0\u6bd4\u7b80\u5355\uff1a<\/p>\n<pre class=\"prettyprint linenums\">-&lt;255:%&gt;- docker run --rm -it ubuntu:20.04 bash\r\nUnable to find image &#039;ubuntu:20.04&#039; locally\r\n20.04: Pulling from library\/ubuntu\r\n7b1a6ab2e44d: Already exists\r\nDigest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322\r\nStatus: Downloaded newer image for ubuntu:20.04\r\n\r\nroot@aa28b038528e:\/# lscpu\r\nArchitecture: x86_64\r\nCPU op-mode(s): 32-bit, 64-bit\r\nByte Order: Little Endian\r\n<\/pre>\n<p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u5728\u5bb9\u5668\u91cc\u4e00\u987f\u64cd\u4f5c\uff0c\u7136\u540e\u6784\u5efa\u51fa\u6765\u4e00\u4e2a\u4e1c\u897f\u62ff\u6765\u7528\uff0c\u6bd4\u5982\u4e4b\u524d\u5728<a href=\"https:\/\/dmesg.app\/fix-ax3600.html\">\u7f16\u8bd1LEDE\u56fa\u4ef6<\/a>\u65f6\uff0c\u6211\u5c31\u662f\u8fd9\u4e48\u73a9\u7684\u3002<\/p>\n<p>\u67d0\u4e00\u5929\uff0c<s>\u6211\u7a81\u7136\u63a5\u5230\u8fd9\u6837\u4e00\u4e2a\u9700\u6c42<\/s>\uff1a\u4f7f\u7528pyinstaller\u628aPython\u811a\u672c\u7f16\u8bd1\u6210\u4e0d\u540c\u5e73\u53f0\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u5e76\u4e14\u8981\u5c3d\u53ef\u80fd\u8dd1\u5728\u5bb9\u5668\u5185\u3002\u8fd9\u600e\u4e48\u505a\uff1f<\/p>\n<ul>\n<li>\u51c6\u5907Windows macOS\u548cLinux\u7684\u673a\u5668\uff0c\u7f16\u8bd1\u7136\u540e\u62ff\u6587\u4ef6\u3002\u592a\u9ebb\u70e6\u4e86<\/li>\n<li>pyinstaller \u4ea4\u53c9\u7f16\u8bd1\uff1f\u4e0d\u597d\u610f\u601dpyinstaller\u4e0d\u652f\u6301\u4ea4\u53c9\u7f16\u8bd1\uff0c\u66f4\u51c6\u786e\u7684\u8bf4\u662f1.5\u7248\u672c\u79fb\u9664\u4e86\u8fd9\u4e2a\u529f\u80fd<\/li>\n<li>Linux container\u8dd1\u4e00\u4e2awine\uff0cwine\u91cc\u8dd1Windows\u7248\u672c\u7684Python\uff1f\u9006\u5411\u5de5\u7a0b\u771f\u7684\u9760\u8c31\u561b\uff1f\u4f1a\u51fa\u73b0\u5f88\u591a\u5947\u5947\u602a\u602a\u7684bug\u5427<\/li>\n<li>\u5728docker\u91cc\u60f3\u529e\u6cd5\u8dd1\u4e2aWindows\uff1f\u54ce\u563f\uff1f<\/li>\n<\/ul>\n<p>\u5f53\u4f60\u5174\u81f4\u52c3\u52c3\u7684\u6253\u5f00Docker Hub\uff0c\u641c\u7d22windows\u53d1\u73b0\u7adf\u7136\u6709Windows\u7684image\uff0cWindows base OS images\uff0cWindows Server Core\uff0c\u4e0d\u7ba1\u4e86\u5148\u8dd1\u4e3a\u656c\uff1a<\/p>\n<pre class=\"prettyprint linenums\">-&lt;130:%&gt;- docker run mcr.microsoft.com\/windows:20H2\r\nUnable to find image &#039;mcr.microsoft.com\/windows:20H2&#039; locally\r\n20H2: Pulling from windows\r\ndocker: no matching manifest for linux\/amd64 in the manifest list entries.\r\nSee &#039;docker run --help&#039;.\r\n<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2021\/12\/2021122518122870.jpeg\" alt=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" title=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" alt=\"ooc\" \/><\/p>\n<p>docker\u5176\u5b9e\u662f\u4f7f\u7528\u4e86Linux\u5185\u6838\u7684cgroup\u7b49\u6280\u672f\u6765\u5b9e\u73b0\u7684\uff0c\u5bb9\u5668\u8fd8\u662f\u4f7f\u7528\u7684\u5bbf\u4e3b\u673a\u5185\u6838\uff0c\u5bb9\u5668\u7684\u8fdb\u7a0b\u5176\u5b9e\u5c31\u662f\u8dd1\u5728\u5bbf\u4e3b\u673a\u4e0a\u7684\uff0c\u5bbf\u4e3b\u673a\u8fd8\u80fd\u770b\u89c1\u53ea\u4e0d\u8fc7\u6709\u4e00\u5b9a\u9694\u79bb\u3002Windows\u5e76\u4e0d\u7528Linux Kernel\uff0c\u90a3\u8dd1\u4e2a\u4ec0\u4e48\u561b\u3002\u4e0a\u9762\u8fd9\u4e9bimage\u7684OS Arch\u5176\u5b9e\u4e5f\u662fwindows\/amd64\u7684\u3002<\/p>\n<p>\u53ef\u80fd\u66f4\u9700\u8981\u7684\u662f\u8fd9\u4e2a,\u786e\u5b9e\u53ef\u4ee5\u8dd1Windows container\uff0c\u53ea\u4e0d\u8fc7\u9700\u8981Windows host\u5566\u3002\u5e76\u4e141709\u7684Windows\u53ea\u80fd\u8dd11709\u7684image<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2021\/12\/2021122518122994.jpeg\" alt=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" title=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" \/><\/p>\n<p>\u8fd9\u4e0d\u5c31\u53c8\u56de\u5230\u4e86\u5f00\u5934\u561b\u3002<\/p>\n<p>\u7a81\u7136\u60f3\u8d77\u6765\u6709\u4e00\u4e2a\u5f88\u795e\u5947\u7684\u9879\u76ee<a href=\"https:\/\/github.com\/sickcodes\/Docker-OSX\">Docker-OSX<\/a>\uff0c\u5176\u5b9e\u73b0\uff0c\u7b80\u5355\u8bf4\u662f\u7528KVM\u8dd1\u4e86\u4e2amacOS\u7684\u865a\u62df\u673a\uff0c\u5c31\u50cf\u9ed1\u82f9\u679c\u4e00\u6837\u3002\u90a3\u4e48\u7406\u8bba\u4e0aWindows\u4e5f\u4e00\u5b9a\u80fd\u627e\u5230\u529e\u6cd5\u505a\u5230\u3002\u90a3\u4e48\u5c31\u4e0aqemu\uff01\u4e0d\u884c\u6211\u4eec\u5c31\u8f6f\u4ef6\u6a21\u62df\uff01<\/p>\n<p><div id=\"sc_blue\"><br \/>\n\u8fd8\u6709\u4e00\u4e2a\u6709\u8da3\u7684\u4e1c\u897f\u53ebdind \u2013 Docker In Docker\u3002<br \/>\n<\/div><br \/>\n\u5957\u5a03\u561b\uff0c\u6211\u6700\u5f3a\u3002<\/p>\n<h2>\u8fd0\u884c\u73af\u5883\u68c0\u67e5<\/h2>\n<p>\u65e0\u8bba\u662fVM\uff0c\u8fd8\u662f\u7269\u7406\u673a\u5176\u5b9e\u90fd\u53ef\u4ee5\u3002<\/p>\n<h2>KVM\u652f\u6301<\/h2>\n<p>\u5982\u679c\u80fd\u6709KVM\u652f\u6301\u7684\u8bdd\uff0c\u865a\u62df\u673a\u5e94\u8be5\u4f1a\u8dd1\u7684\u66f4\u6d41\u7545\u3002<\/p>\n<p>\u5982\u679c\u4f60\u662fVM\uff0cCPU\u652f\u6301Intel VT-x\/ AMD-v\u7b49\uff0c\u90a3\u4e48\u5728\u865a\u62df\u5316\u8f6f\u4ef6\u7684\u8bbe\u7f6e\u4e2d\u5c31\u53ef\u4ee5\u770b\u5230<\/p>\n<p>ESXi\u662f\u8fd9\u6837\u7684<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2021\/12\/2021122518123126.png\" alt=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" title=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" \/><\/p>\n<p>Fusion\u662f\u8fd9\u6837\u7684<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2021\/12\/2021122518123260.png\" alt=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" title=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" \/><\/p>\n<p>\u52fe\u9009\u4e4b\u540e\uff0c <code>ls \/dev\/kvm<\/code> \u5c31\u5e94\u8be5\u6709\u7ed3\u679c\u5566<\/p>\n<h2>\u5bb9\u5668\u542f\u7528 privileged mode<\/h2>\n<p><code>docker run --privileged xxx<\/code>\u5373\u53ef\uff0c\u4e3b\u8981\u662f\u4e3a\u4e86\u80fd\u591f\u5728\u5bb9\u5668\u5185\u8bbf\u95ee\u5bbf\u4e3b\u673a\u7684<code>\/dev\/kvm<\/code>\u3002\u5f53\u7136\u4e5f\u53ef\u4ee5\u7528<code>--device<\/code><\/p>\n<h2>\u5728\u5bb9\u5668\u5185\u51c6\u5907qemu\u4e00\u7ba9\u7b50<\/h2>\n<p>\u4ee5Ubuntu 20.04\u4e3a\u4f8b<\/p>\n<pre class=\"prettyprint linenums\">apt update &amp;&amp; apt install qemu-kvm\r\n<\/pre>\n<h2>\u51c6\u5907ISO<\/h2>\n<p>\u4ee5alpine\u4e3a\u4f8b\uff0c\u65b9\u4fbf\u6d4b\u8bd5<\/p>\n<pre class=\"prettyprint linenums\">wget https:\/\/dl-cdn.alpinelinux.org\/alpine\/v3.15\/releases\/x86_64\/alpine-virt-3.15.0-x86_64.iso\r\n<\/pre>\n<h2>\u521b\u5efavm\u5e76\u542f\u52a8<\/h2>\n<p>\u4e3a\u4e86PoC\uff0c\u6211\u4eec\u76f4\u63a5\u521b\u5efavm\u7136\u540e\u542f\u52a8\u8bd5\u8bd5\u770b\uff0c<code>-nographic<\/code>\u56e0\u4e3a\u6211\u4eec\u5728CLI\u4e0b\uff0c\u6240\u4ee5\u4e0d\u542f\u7528\u56fe\u5f62\u754c\u9762\uff0c<code>-enable-kvm<\/code>\u56e0\u4e3a\u5bbf\u4e3b\u673a\u6709kvm\u652f\u6301\uff0c<code>-cdrom<\/code>\u6307\u5b9a\u5149\u9a71<\/p>\n<pre class=\"prettyprint linenums\">qemu-system-x86_64 -nographic -enable-kvm -cdrom \/root\/alpine-virt-3.15.0-x86_64.iso\r\n<\/pre>\n<p>\u610f\u6599\u4e4b\u4e2d\uff0c\u51fa\u73b0\u4e86Alpine\u7684\u542f\u52a8\u753b\u9762<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2021\/12\/2021122518123522.png\" alt=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" title=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" \/><\/p>\n<p>\u5e76\u4e14\u80fd\u770b\u5230qemu\u9ed8\u8ba4\u914d\u7f6e\u7684\u5185\u5b58\u548cCPU\u3002\u8fd9\u4e2aQEMU Virtual CPU\u662f\u4e0d\u662f\u5728\u67d0\u4e9bVPS\u4e2d\u770b\u5230\u8fc7\u5462\uff1f<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2021\/12\/2021122518123780.png\" alt=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" title=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" \/><\/p>\n<p>\u60f3\u8981\u9000\u51faqemu\uff0c\u5148\u6309ctrl a\uff0c\u7136\u540e\u677e\u5f00\uff0c\u8fc5\u901f\u6309x<\/p>\n<h2>\u4f7f\u7528VNC<\/h2>\n<p>\u65e2\u7136\u65e0\u56fe\u5f62\u754c\u9762\u7684alpine\u53ef\u4ee5\uff0c\u90a3\u4e48\u5b89\u88c5\u4e2aUbuntu Desktop\u4e5f\u4e00\u5b9a\u53ef\u4ee5\u3002<\/p>\n<p>\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5c31\u9700\u8981\u6211\u4eec\u4f7f\u7528VNC\u5566\u3002<\/p>\n<p>VNC\u7684\u9ed8\u8ba4\u7aef\u53e3\u662f5900\uff0c\u6211\u4eec\u8981\u5728\u542f\u52a8\u5bb9\u5668\u7684\u65f6\u5019\u540c\u65f6publish\u8fd9\u4e2a\u7aef\u53e3\uff0c\u65b9\u4fbf\u6211\u4eec\u4f7f\u7528VNC\u5ba2\u6237\u7aef<\/p>\n<pre class=\"prettyprint linenums\">docker run --rm --privileged -p 5900:5900 -it -v $(pwd):\/root\/ bennythink\/vmid bash\r\n<\/pre>\n<p>\u7531\u4e8eUbuntu Desktop\u9700\u8981\u6bd4\u8f83\u591a\u7684\u5185\u5b58\u548cCPU\uff0c\u56e0\u6b64\u6211\u4eec\u8fd9\u91cc\u4e5f\u591a\u52a0\u51e0\u4e2a\u53c2\u6570<\/p>\n<pre class=\"prettyprint linenums\">qemu-system-x86_64 -nographic -enable-kvm -m 4096 -cpu host -smp 2 -cdrom \/root\/ubuntu-20.04.3-desktop-amd64.iso.iso -vnc 0.0.0.0:0\r\n<\/pre>\n<p><code>-m<\/code>\u8868\u793a\u5185\u5b58\u5927\u5c0f\uff0c\u5355\u4f4d\u662fMiB\uff0c\u4e5f\u53ef\u4ee5 <code>-m 2g<\/code>\u8868\u793a2GiB\u7684\u5185\u5b58<\/p>\n<p><code>-cpu<\/code>\u8868\u793aCPU\u7c7b\u578b\uff0c\u4e4b\u524d\u4e0a\u9762\u6211\u4eec\u770b\u5230CPU\u662fQEMU Virtual CPU\uff0c\u5728\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u6307\u5b9aCPU\uff0c\u6bd4\u5982 <code>-cpu EPYC<\/code> \u8868\u793a\u865a\u62df\u673a\u770b\u5230\u7684CPU\u662fAMD EPYC\uff0c\u5f53\u7136\u4e5f\u8981\u5ba1\u65f6\u5ea6\u52bf\uff0c\u4f60\u4e00\u4e2ax86-64\u7684image\uff0c\u5c31\u522b\u60f3\u7740\u7528486\u4e86\u3002\u6709\u51e0\u4e2a\u7279\u6b8a\u7684\u503c\uff1a<code>host<\/code>\u8868\u793a\u4f7f\u7528\u548c\u5bbf\u4e3b\u673a\u4e00\u6837\u7684CPU\uff0cbase\u7684\u8bdd\u6bd4\u8f83\u9e21\u808b\u987e\u540d\u601d\u4e49\u5c31\u662f\u57fa\u7840\u7684\u4ec0\u4e48\u6307\u4ee4\u96c6\u90fd\u6ca1\u6709\uff0cmax\u4f1a\u628a\u6240\u6709\u7684\u652f\u6301\u7684\u6307\u4ee4\u96c6\u548ckvm\u80fd\u63d0\u4f9b\u7684\u6307\u4ee4\u96c6\u90fd\u52a0\u4e0a\u3002<\/p>\n<p><code>-smp<\/code>\u5c31\u662f\u51e0\u6838\u5fc3\u7684CPU\u5566\uff0c\u8fd9\u8981\u770b\u5bbf\u4e3b\u673a\u91cf\u529b\u800c\u884c\u3002\u5c31\u50cfmake\u65f6\u8981\u91cf\u529b\u800c\u884c\u4e00\u6837<\/p>\n<p><code>-vnc<\/code>\u8868\u793a\u4f7f\u7528VNC\uff0c0.0.0.0\u8868\u793a\u76d1\u542c0.0.0.0\uff0c\u5192\u53f7\u540e\u76840\u8868\u793a5900\uff0c\u5982\u679c\u7528<code>0.0.0.0:1<\/code>\uff0c\u90a3\u4e48\u76d1\u542c\u7684\u7aef\u53e3\u5c31\u662f5901\u5566\uff0c\u8981\u6ce8\u610f\u54e6\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5f00\u542f\u7684VNC\u662f\u6ca1\u6709\u5bc6\u7801\u7684\uff0c\u5982\u679c\u60f3\u8981\u5bc6\u7801\u90a3\u5c31 <code>-vnc 0.0.0.0:0,password<\/code> \u7136\u540e\u8bbe\u7f6e\u5bc6\u7801\u2026\u2026 \u6bd4\u8f83\u590d\u6742\uff0c\u5efa\u8bae\u653e\u5f03\u3002<\/p>\n<p>\u7136\u540e\u4f7f\u7528VNC\u5ba2\u6237\u7aef\u8fde\u63a5\u5373\u53ef\uff0c\u8981\u6ce8\u610fmacOS\u81ea\u5e26\u7684VNC\u5ba2\u6237\u7aef\u9700\u8981\u5bc6\u7801\uff0c\u4f46\u662f\u6211\u4eec\u5e76\u6ca1\u6709\u8bbe\u7f6e\u5bc6\u7801\uff0c\u56e0\u6b64\u662f\u7528\u4e0d\u4e86\u7684\u3002\u4f7f\u7528VNC viewer\u53ef\u7834<\/p>\n<pre class=\"prettyprint linenums\">brew install --cask vnc-viewer\r\n<\/pre>\n<p><div id=\"sc_blue\">\u8fa3\u9e21macOS\u81ea\u5e26\u7684VNC Client\u4e5f\u8fde\u4e0d\u4e0a127.0.0.1\u7684\uff0c\u8fa3\u9e21\u3002<br \/>\n<\/div><br \/>\n<img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2021\/12\/2021122518124036.png\" alt=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" title=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" \/><\/p>\n<p>\u6211\u4eec\u5df2\u7ecf\u80fd\u591f\u770b\u5230Ubuntu\u7684\u5b89\u88c5\u754c\u9762\u5566\uff0c\u5e76\u4e14\u5728\u8fd9\u53f0VM\u4e2d\uff0c\u7f51\u7edc\u4e5f\u662f\u901a\u7684\uff0cQEMU\u5206\u914d\u4e86\u4e00\u4e2a10\u6bb5IP.\u5982\u679c\u4f60\u53d1\u73b0\u4e0d\u80fdping\uff0c\u90a3\u4e48\u5728host\u4e2d <code>sysctl -w net.ipv4.ping_group_range='0 2147483647'<\/code>\u5c31\u53ef\u4ee5\u5566\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2021\/12\/2021122518124692.png\" alt=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" title=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" \/><\/p>\n<h2>\u5206\u914d\u78c1\u76d8<\/h2>\n<p>\u50cf\u5f80\u5e38\u4f7f\u7528\u865a\u62df\u673a\u4e00\u6837\uff0c\u6211\u4eec\u4e5f\u9700\u8981\u4e3a\u865a\u62df\u673a\u5206\u914d\u4e00\u4e2a\u865a\u62df\u78c1\u76d8\uff0c\u8fd9\u6837\u624d\u80fd\u591f\u5b89\u88c5\u64cd\u4f5c\u7cfb\u7edf\u3002\u603b\u4e0d\u80fd\u6bcf\u6b21\u90fd\u4ece\u5149\u76d8\u542f\u52a8\u5427\u3002\u5206\u914d\u865a\u62df\u78c1\u76d8\u4e5f\u6709\u5f88\u591a\u8bb2\u7a76\uff0c\u6bd4\u598210G\u662f\u4e00\u4e0b\u5b50\u90fd\u5206\u914d\u4e86\uff0c\u8fd8\u662f\u7528\u591a\u5c11\u5206\u914d\u591a\u5c11\uff1f<\/p>\n<pre class=\"prettyprint linenums\">qemu-img create -f qcow2 \/root\/test.qcow2 16G\r\n<\/pre>\n<p>-f \u8868\u793a\u865a\u62df\u78c1\u76d8\u7684\u683c\u5f0f\uff0c\u652f\u6301raw\u548cqcow2\uff0craw\u987e\u540d\u601d\u4e49\u5c31\u662f\u539f\u59cb\u7684\uff0c\u5bf9vm\u6765\u8bf4\u5c31\u662f\u4e00\u4e2a\u5757\u8bbe\u5907\u3002\u5982\u679cvm\u6587\u4ef6\u7cfb\u7edf\u652f\u6301\u7a7a\u6d1e\uff0c\u90a3\u4e48raw\u662f\u4e00\u70b9\u70b9\u586b\u6ee1\u7684\uff0craw\u6027\u80fd\u8f83\u597d\u3002qcow2\u662fqemu\u63a8\u8350\u7684\u683c\u5f0f\uff0c\u652f\u6301\u52a0\u5bc6\u5feb\u7167\u7b49\u7b49\uff0c\u522b\u60f3\u4e86\u5c31\u8fd9\u4e2a\u5427\u3002\u5f53\u7136qemu\u8fd8\u652f\u6301vmdk\u3001vdi\u4e4b\u7c7b\u7684\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u522b\u7ed9\u78c1\u76d8\u6491\u7206\u4e86\u3002<\/p>\n<h2>\u5b89\u88c5Ubuntu Desktop<\/h2>\n<p>\u521b\u5efa\u597d\u78c1\u76d8\u4e4b\u540e\uff0c\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u5373\u53ef\u5f00\u59cb\u5f00vm\u5b89\u88c5Ubuntu<\/p>\n<pre class=\"prettyprint linenums\">qemu-system-x86_64 -nographic -enable-kvm -m 4096 -cpu host -smp 4 -drive file=\/root\/test.qcow2 -cdrom \/root\/ubuntu-20.04.3-desktop-amd64.iso -vnc 0.0.0.0:0\r\n<\/pre>\n<p>\u5b89\u88c5\u8fc7\u7a0b\u548c\u666e\u901aVM\u6ca1\u4ec0\u4e48\u5dee\u522b\uff0c\u5c31\u662f\u2026\u2026 \u6162\u4e86\u70b9\u3002<\/p>\n<h2>\u542f\u52a8VM<\/h2>\n<p>\u5b89\u88c5\u597d\u4e4b\u540e\uff0c\u4e0b\u6b21\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u542f\u52a8VM\u4e86\uff0c\u53ef\u4ee5\u5220\u6389-cdrom\u53c2\u6570<\/p>\n<pre class=\"prettyprint linenums\">qemu-system-x86_64 -nographic -enable-kvm -m 4096 -cpu host -smp 4 -drive file=\/root\/test.qcow2 -vnc 0.0.0.0:0\r\n<\/pre>\n<h2>\u8dd1arm\u2026\u2026<\/h2>\n<p>\u90fd\u77e5\u9053qemu\u662f\u4e2a\u6a21\u62df\u795e\u5668\uff0c\u60f3\u8981\u8dd1arm\u4e5f\u4e0d\u662f\u4e0d\u53ef\u80fd\uff0c\u6bd4\u5982\u8dd1\u4e2aliveCD\u505a\u4e2a\u6d4b\u8bd5\u4ec0\u4e48\u7684\uff1a<\/p>\n<pre class=\"prettyprint linenums\">apt install qemu-system-arm\r\n\r\ndd if=\/dev\/zero of=flash0.img bs=1M count=64\r\ndd if=\/usr\/share\/qemu-efi\/QEMU_EFI.fd of=flash0.img conv=notrunc\r\ndd if=\/dev\/zero of=flash1.img bs=1M count=64\r\n\r\nqemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt -nographic -pflash flash0.img -pflash flash1.img -drive if=none,file=alpine-virt-3.15.0-aarch64.iso,id=hd0 -device virtio-blk-device,drive=hd0 -net nic -net user\r\n<\/pre>\n<p>\u8fd9\u6b21\u542f\u52a8\u7684\u901f\u5ea6\u5c31\u4f1a\u975e\u5e38\u6162\u4e86\uff0c\u5982\u679c\u542f\u52a8\u6210\u529f\u4e4b\u540e\u6ca1\u6709\u7f51\u7edc\uff0c\u90a3\u4e48\u8981\u5f00\u4e0bdhcp\uff0c\u4ee5alpine\u4e3a\u4f8b<\/p>\n<pre class=\"prettyprint linenums\">vi \/etc\/network\/interfaces\r\n\r\nauto lo\r\niface lo inet loopback\r\nauto eth0\r\niface eth0 inet dhcp\r\n<\/pre>\n<p>\u7136\u540e<code>ifup eth0<\/code>\u5373\u53ef<\/p>\n<p>\u5982\u679c\u60f3\u8981\u5b89\u88c5\u5230\u67d0\u4e2a\u78c1\u76d8\u4e2d\uff0c\u62ffUbuntu\u4e3a\u4f8b<\/p>\n<pre class=\"prettyprint linenums\">qemu-img create -f qcow2 ubuntu.qcow2 8G\r\n\r\nmount -o loop ubuntu-20.04.3-live-server-arm64.iso \/mnt\r\n\r\ncp \/mnt\/casper\/vmlinuz .\/\r\ncp \/mnt\/casper\/initrd .\/\r\n\r\nqemu-system-aarch64 -m 1024 -cpu cortex-a57 -smp cpus=4 -M virt -nographic \\\r\n-kernel .\/vmlinuz -initrd .\/initrd \\\r\n-drive file=ubuntu.qcow2,if=none,format=qcow2,id=hd0 -device virtio-blk-device,drive=hd0 \\\r\n-drive file=ubuntu-20.04.3-live-server-arm64.iso,if=none,format=raw,id=hd1 -device virtio-blk-device,drive=hd1 \\\r\n-net nic -net user\r\n<\/pre>\n<p>\u4e4b\u540e\u5f00\u59cb\u6b63\u5e38\u7684\u5b89\u88c5\u6b65\u9aa4\uff0c\u4f1a\u6bd4\u8f83\u6162\uff0c\u800c\u4e14\u7535\u8111\u8d77\u98de\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2021\/12\/2021122518124721.png\" alt=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" title=\"\u4f7f\u7528Docker\u8dd1Windows\uff01\" \/><\/p>\n<p>\u5b89\u88c5\u597d\u5c31\u53ef\u4ee5\u53bb\u6389iso\u90a3\u884c\u5355\u72ec\u542f\u52a8\u4e86\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0cDocker \u7684Multi Arch build\u4e5f\u662f\u6070\u5de7\u5229\u7528\u4e86QEMU\u5566\u3002<\/p>\n<h2>binfmt<\/h2>\n<p>\u5982\u679c\u53ea\u662f\u7b80\u5355\u7684\u60f3\u8981\u8dd1\u4e0b\u5f02\u6784\u7684image\u7684\u8bdd\uff0c\u53ef\u4ee5\u8bd5\u8bd5<a href=\"https:\/\/zh.wikipedia.org\/wiki\/Binfmt_misc\" target=\"_blank\" rel=\"noopener\">binfmt<\/a>\uff0cWindows\u548cMac\u7684Docker Desktop\u76f4\u63a5\u652f\u6301\uff0cLinux\u9700\u8981\u5148\u8fd9\u6837\uff1a<\/p>\n<pre class=\"prettyprint linenums\">docker run --rm --privileged docker\/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d\r\n<\/pre>\n<p>\u7136\u540e\u8dd1\u5427<\/p>\n<pre class=\"prettyprint linenums\">docker run -it --platform linux\/arm64 alpine sh\r\n<\/pre>\n<h2>\u4f7f\u7528\u5df2\u6709\u7684cloud image<\/h2>\n<p>\u6211\u4eec\u5f53\u7136\u53ef\u4ee5\u9009\u62e9\u628aOS\u5b89\u88c5\u5230\u865a\u62df\u78c1\u76d8\u4e2d\uff0c\u4f46\u662f\u8fd9\u6837\u8981\u9ebb\u70e6\u4e00\u4e9b\uff0c\u5b89\u88c5\u8fc7\u7a0b\u6bd4\u8f83\u7e41\u7410\u800c\u4e14\u5f88\u6162\u3002\u6709\u6ca1\u6709\u529e\u6cd5\u7528\u522b\u4eba\u5df2\u7ecf\u51c6\u5907\u597d\u7684qcow2\u5462\uff1f<\/p>\n<p>\u5f53\u7136\u6709\u5566\u3002\u5bf9\u4e8eUbuntu\u6765\u8bf4\uff0c\u53ef\u4ee5\u53bb\u4e0b\u8f7dcloud image\uff0cimg\u7ed3\u5c3e\u7684\u5c31\u662f <a href=\"https:\/\/cloud-images.ubuntu.com\/focal\/current\/\">https:\/\/cloud-images.ubuntu.com\/focal\/current\/<\/a><\/p>\n<p>\u7136\u540e\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2auser data\u6765\u521d\u59cb\u5316\u6211\u4eec\u7684\u5bc6\u7801<\/p>\n<pre class=\"prettyprint linenums\">cat &gt;user-data &lt;&lt;EOF\r\n#cloud-config\r\npassword: 123456\r\nchpasswd: { expire: False }\r\nssh_pwauth: True\r\nEOF\r\n\r\ncloud-localds user-data.img user-data\r\n\r\nqemu-system-x86_64 -nographic -enable-kvm -m 2048 -cpu host -smp 4 -drive file=\/root\/focal-server-cloudimg-amd64.img -drive file=user-data.img,format=raw\r\n<\/pre>\n<p>\u7b49\u5f85\u542f\u52a8\uff0c\u7528\u6237\u540dubuntu\u5bc6\u7801123456<\/p>\n<p>\u4e4b\u540e\u4f60\u7684\u6240\u6709\u66f4\u6539\u5b9e\u9645\u4e0a\u90fd\u4f1a\u5199\u5165\u5230\u8fd9\u4e2aimg\u6587\u4ef6\u4e2d\uff0c\u4e0b\u6b21\u542f\u52a8\u7684\u65f6\u5019\u5c31\u4e0d\u7528user-data\u5566\u3002<\/p>\n<p>\u90a3\u8fd9\u4e2aimg\u53ea\u67092G\uff0c\u4e0d\u591f\u7528\u600e\u4e48\u529e\uff1f<code>qemu-img<\/code>\u6269\u5bb9\uff01<\/p>\n<pre class=\"prettyprint linenums\">root@e769eaf9e4ab:~# qemu-img resize focal-server-cloudimg-amd64.img +5G\r\nImage resized.\r\n\r\nroot@e769eaf9e4ab:~# qemu-img info focal-server-cloudimg-amd64.img\r\nimage: focal-server-cloudimg-amd64.img\r\nfile format: qcow2\r\nvirtual size: 7.2 GiB (7730102272 bytes)\r\ndisk size: 601 MiB\r\ncluster_size: 65536\r\nFormat specific information:\r\ncompat: 0.10\r\nrefcount bits: 16\r\n<\/pre>\n<p>\u7136\u540e\u2026\u2026 \u5982\u679c\u6709LVM\uff0c\u90a3\u5c31\u597d\u529e\u4e86\uff0c\u5982\u679c\u6ca1LVM\uff0c\u90a3\u5c31liveCD\u6269\u5bb9\u5427\u3002\u6240\u4ee5\u5efa\u8bae\u4e00\u5f00\u59cb\u5c31<code>qemu-img resize<\/code>\u597d\u3002<\/p>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<p><a href=\"https:\/\/github.com\/kholia\/OSX-KVM\">https:\/\/github.com\/kholia\/OSX-KVM<\/a><\/p>\n<p><a href=\"https:\/\/blog.ihomura.cn\/2020\/11\/12\/%E5%9C%A8qemu-system%E4%B8%8A%E8%B7%91arm-Debian\/\">https:\/\/blog.ihomura.cn\/2020\/11\/12\/%E5%9C%A8qemu-system%E4%B8%8A%E8%B7%91arm-Debian\/<\/a><\/p>\n<p><a href=\"https:\/\/hub.docker.com\/repository\/docker\/bennythink\/vmid\">https:\/\/hub.docker.com\/repository\/docker\/bennythink\/vmid<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7cbe\u795e\u75c5\u4eba\u53c8\u6765\u95f9\u5996\u5566\uff01 \u81ea\u4ece\u6709\u4e86\u8fd9\u79cd\u5bb9\u5668\u5316\u6280\u672f\u4e4b\u540e\uff0c\u60f3\u8981\u505a\u6d4b\u8bd5\uff0c\u6784\u5efa\u70b9\u4ec0\u4e48\uff0c\u6216\u8005\u7b80\u5355\u7684\u4f53\u9a8c\u4e0b\u67d0\u4e2aLinux D [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[45],"tags":[],"class_list":["post-5118","post","type-post","status-publish","format-standard","hentry","category-what"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts\/5118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/comments?post=5118"}],"version-history":[{"count":8,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts\/5118\/revisions"}],"predecessor-version":[{"id":5135,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts\/5118\/revisions\/5135"}],"wp:attachment":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/media?parent=5118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/categories?post=5118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/tags?post=5118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}