{"id":896,"date":"2023-09-26T15:52:05","date_gmt":"2023-09-26T07:52:05","guid":{"rendered":"https:\/\/blog.espnlol.com\/?p=896"},"modified":"2023-11-17T17:45:12","modified_gmt":"2023-11-17T09:45:12","slug":"%e4%bd%bf%e7%94%a8-buildx-%e6%9e%84%e5%bb%ba%e5%a4%9a%e7%a7%8d%e7%b3%bb%e7%bb%9f%e6%9e%b6%e6%9e%84%e6%94%af%e6%8c%81%e7%9a%84-docker-%e9%95%9c%e5%83%8f","status":"publish","type":"post","link":"https:\/\/blog.espnlol.com\/?p=896","title":{"rendered":"\u4f7f\u7528 buildx \u6784\u5efa\u591a\u79cd\u7cfb\u7edf\u67b6\u6784\u652f\u6301\u7684 Docker \u955c\u50cf"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1\u3001<strong>\u8de8 CPU \u67b6\u6784\u7f16\u8bd1\u7a0b\u5e8f\u7684\u65b9\u6cd5<\/strong><\/h2>\n\n\n\n<p>\u5728 Linux \u4e0a\uff0c<code>QEMU<\/code>&nbsp;\u9664\u4e86\u53ef\u4ee5\u6a21\u62df\u5b8c\u6574\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e4b\u5916\uff0c\u8fd8\u6709\u53e6\u5916\u4e00\u79cd\u6a21\u5f0f\u53eb<code>\u7528\u6237\u6001\u6a21\u5f0f<\/code>\uff08User mod\uff09\u3002\u8be5\u6a21\u5f0f\u4e0b QEMU \u5c06\u901a\u8fc7&nbsp;binfmt_misc&nbsp;\u5728 Linux \u5185\u6838\u4e2d\u6ce8\u518c\u4e00\u4e2a\u4e8c\u8fdb\u5236\u8f6c\u6362\u5904\u7406\u7a0b\u5e8f\uff0c\u5e76\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u52a8\u6001\u7ffb\u8bd1\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u6839\u636e\u9700\u8981\u5c06\u7cfb\u7edf\u8c03\u7528\u4ece\u76ee\u6807 CPU \u67b6\u6784\u8f6c\u6362\u4e3a\u5f53\u524d\u7cfb\u7edf\u7684 CPU \u67b6\u6784\u3002\u6700\u7ec8\u7684\u6548\u679c\u770b\u8d77\u6765\u5c31\u50cf\u5728\u672c\u5730\u8fd0\u884c\u76ee\u6807 CPU \u67b6\u6784\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7 QEMU \u7684\u7528\u6237\u6001\u6a21\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u8f7b\u91cf\u7ea7\u7684\u865a\u62df\u673a\uff08chroot&nbsp;\u6216\u5bb9\u5668\uff09\uff0c\u7136\u540e\u5728\u865a\u62df\u673a\u7cfb\u7edf\u4e2d\u7f16\u8bd1\u7a0b\u5e8f\uff0c\u548c\u672c\u5730\u7f16\u8bd1\u4e00\u6837\u7b80\u5355\u8f7b\u677e\u3002\u540e\u9762\u6211\u4eec\u5c31\u4f1a\u770b\u5230\uff0c\u8de8\u5e73\u53f0\u6784\u5efa Docker \u955c\u50cf\u7528\u7684\u5c31\u662f\u8fd9\u4e2a\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2\u3001\u4e0b\u8f7dbuildx\u7f16\u8bd1\u5de5\u5177<\/h2>\n\n\n\n<p>\u4f20\u9001\u95e8:<a href=\"https:\/\/github.com\/docker\/buildx\">https:\/\/github.com\/docker\/buildx<\/a>,\u4f7f\u7528\u6700\u65b0\u7248\u5373\u53ef<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wget https:\/\/github.com\/docker\/buildx\/releases\/download\/v0.11.2\/buildx-v0.11.2.linux-amd64 -O \/usr\/bin\/buildx\nchmod 755 \/usr\/bin\/buildx<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3\u3001<strong>\u542f\u7528 binfmt_misc<\/strong><\/h2>\n\n\n\n<p>\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f Docker \u684c\u9762\u7248\uff08MacOS \u548c Windows\uff09\uff0c\u9ed8\u8ba4\u5df2\u7ecf\u542f\u7528\u4e86&nbsp;<code>binfmt_misc<\/code>\uff0c\u53ef\u4ee5\u8df3\u8fc7\u8fd9\u4e00\u6b65\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f Linux\uff0c\u9700\u8981\u624b\u52a8\u542f\u7528&nbsp;<code>binfmt_misc<\/code>\u3002\u5927\u591a\u6570 Linux \u53d1\u884c\u7248\u90fd\u5f88\u5bb9\u6613\u542f\u7528\uff0c\u4e0d\u8fc7\u8fd8\u6709\u4e00\u4e2a\u66f4\u5bb9\u6613\u7684\u529e\u6cd5\uff0c\u76f4\u63a5\u8fd0\u884c\u4e00\u4e2a\u7279\u6743\u5bb9\u5668\uff0c\u5bb9\u5668\u91cc\u9762\u5199\u597d\u4e86\u8bbe\u7f6e\u811a\u672c\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker run --rm --privileged tonistiigi\/binfmt --install all\ninstalling: s390x OK\ninstalling: ppc64le OK\ninstalling: mips64le OK\ninstalling: arm OK\ninstalling: riscv64 OK\ninstalling: 386 OK\ninstalling: mips64 OK\ninstalling: amd64 OK\n{\n  \"supported\": [\n    \"linux\/arm64\",\n    \"linux\/amd64\",\n    \"linux\/riscv64\",\n    \"linux\/ppc64le\",\n    \"linux\/s390x\",\n    \"linux\/386\",\n    \"linux\/mips64le\",\n    \"linux\/mips64\",\n    \"linux\/arm\/v7\",\n    \"linux\/arm\/v6\"\n  ],\n  \"emulators\": [\n    \"qemu-arm\",\n    \"qemu-i386\",\n    \"qemu-mips64\",\n    \"qemu-mips64el\",\n    \"qemu-ppc64le\",\n    \"qemu-riscv64\",\n    \"qemu-s390x\",\n    \"qemu-x86_64\"\n  ]\n}\n\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4\u3001\u6784\u5efa\u5e76\u4e0a\u4f20\u955c\u50cf<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">#\u521b\u5efadockerfile\nFROM --platform=$TARGETPLATFORM openjdk:8u342-jdk-slim\nMAINTAINER ae\nCOPY .\/rocketmq-dashboard.jar \/\nENTRYPOINT [\"sh\",\"-c\",\"java $JAVA_OPTS -jar \/rocketmq-dashboard.jar\"]\n\n#\u901a\u8fc7platform\u6307\u5b9a\u8981\u6784\u5efa\u7684\u73af\u5883\uff0c\u901a\u8fc7push\u63a8\u5230\u8fdc\u7a0b\u4ed3\u5e93\u5373\u53ef\n<strong>buildx<\/strong> build --platform linux\/arm64,linux\/amd64 -t congcong126\/openvpn-ldap-otp:v1.5 . --push<\/pre>\n\n\n\n<p>5\u3001\u6545\u969c\u6392\u67e5<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#\u62a5\u9519ERROR: Multiple platforms feature is currently not supported for docker driver. Please switch to a different driver (eg. \"docker buildx create --use\")\uff0c\u53ef\u80fd\u662f\u4f4e\u7248\u672c\u4e0d\u652f\u6301\uff0c\u9ad8\u7248\u672c\u53ef\u6267\u884c\nbuildx create --name multi-platform  --use --platform linux\/amd64,linux\/arm64 --driver docker-container<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u8de8 CPU \u67b6\u6784\u7f16\u8bd1\u7a0b\u5e8f\u7684\u65b9\u6cd5 \u5728 Linux \u4e0a\uff0cQEMU&nbsp;\u9664\u4e86 &hellip; <a href=\"https:\/\/blog.espnlol.com\/?p=896\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-896","post","type-post","status-publish","format-standard","hentry","category-k8s"],"_links":{"self":[{"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=\/wp\/v2\/posts\/896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=896"}],"version-history":[{"count":3,"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=\/wp\/v2\/posts\/896\/revisions"}],"predecessor-version":[{"id":914,"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=\/wp\/v2\/posts\/896\/revisions\/914"}],"wp:attachment":[{"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.espnlol.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}