{"id":372,"date":"2021-08-22T02:48:00","date_gmt":"2021-08-22T02:48:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=372"},"modified":"2021-08-22T02:48:00","modified_gmt":"2021-08-22T02:48:00","slug":"372","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/08\/22\/372\/","title":{"rendered":"\u6784\u5efa\u591a\u5e73\u53f0 Docker \u955c\u50cf"},"content":{"rendered":"<h1>\u6784\u5efa\u591a\u5e73\u53f0 Docker \u955c\u50cf<\/h1>\n<p>\u5229\u7528 Docker \u5f15\u5165\u7684\u63d2\u4ef6 buildx\uff0c\u53ef\u4ee5\u5f88\u8f7b\u677e\u5730\u6784\u5efa\u591a\u5e73\u53f0 Docker \u955c\u50cf\u3002buildx \u662f docker build ... \u547d\u4ee4\u7684\u4e0b\u4e00\u4ee3\u66ff\u4ee3\u54c1\uff0c\u5b83\u5229\u7528 BuildKit \u7684\u5168\u90e8\u529f\u80fd\u6269\u5c55\u4e86 docker build \u7684\u529f\u80fd\u3002<\/p>\n<h3>\u4f7f\u7528\u4e00\u884c\u547d\u4ee4\u5c31\u53ef\u4ee5\uff0c\u4e09\u4e2a\u5e73\u53f0\u540c\u65f6\u7f16\u8bd1\u6253\u5305\u548c\u63a8\u9001\u5230\u8fdc\u7a0b <code>DockerHub<\/code><\/h3>\n<pre><code>docker buildx build -t hongwenjun\/ip \\r\n--platform=linux\/arm,linux\/arm64,linux\/amd64 . --push<\/code><\/pre>\n<p>\u4e0b\u9762\u5c31\u6765\u6f14\u793a\u4e00\u4e0b\u5982\u4f55\u5728\u77ed\u77ed\u51e0\u5206\u949f\u5185\u4f7f\u7528 buildx \u6784\u5efa\u51fa\u4e0d\u540c\u5e73\u53f0\u7684 Docker \u955c\u50cf\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<h2>\u542f\u7528 buildx \u63d2\u4ef6<\/h2>\n<pre><code>export DOCKER_CLI_EXPERIMENTAL=enabled\n\ndocker buildx version\n# github.com\/docker\/buildx v0.6.1-docker 260d07a9a19b03df969787496419a0808a27ac61\n<\/code><\/pre>\n<h2>\u542f\u7528 binfmt_misc<\/h2>\n<pre><code>docker pull docker\/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64\ndocker run --rm --privileged docker\/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64\n<\/code><\/pre>\n<h2>\u9a8c\u8bc1\u662f binfmt_misc \u5426\u5f00\u542f\uff1a<\/h2>\n<pre><code>ls -al \/proc\/sys\/fs\/binfmt_misc\/\n\n-rw-r--r-- 1 root root 0 Aug 22 02:33 qemu-aarch64\n-rw-r--r-- 1 root root 0 Aug 22 02:33 qemu-arm\n-rw-r--r-- 1 root root 0 Aug 22 02:33 qemu-ppc64le\n-rw-r--r-- 1 root root 0 Aug 22 02:33 qemu-riscv64\n-rw-r--r-- 1 root root 0 Aug 22 02:33 qemu-s390x\n<\/code><\/pre>\n<h2>\u9a8c\u8bc1\u662f\u5426\u542f\u7528\u4e86\u76f8\u5e94\u7684\u5904\u7406\u5668\uff1a<\/h2>\n<pre><code>cat \/proc\/sys\/fs\/binfmt_misc\/qemu-aarch64\n\nenabled\ninterpreter \/usr\/bin\/qemu-aarch64\nflags: OCF\noffset 0\nmagic 7f454c460201010000000000000000000200b7\nmask ffffffffffffff00fffffffffffffffffeffff<\/code><\/pre>\n<h2>\u4ece\u9ed8\u8ba4\u7684\u6784\u5efa\u5668\u5207\u6362\u5230\u591a\u5e73\u53f0\u6784\u5efa\u5668<\/h2>\n<h3>1. \u5148\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6784\u5efa\u5668\uff1a<\/h3>\n<pre><code>docker buildx create --use --name mybuilder\n<\/code><\/pre>\n<h3>2. \u542f\u52a8\u6784\u5efa\u5668\uff1a<\/h3>\n<pre><code>docker buildx inspect mybuilder --bootstrap\n\n[+] Building 6.9s (1\/1) FINISHED\n =&gt; [internal] booting buildkit                                                                                                                                        6.8s\n =&gt; =&gt; pulling image moby\/buildkit:buildx-stable-1                                                                                                                     5.8s\n =&gt; =&gt; creating container buildx_buildkit_mybuilder0                                                                                                                   1.0s\nName:   mybuilder\nDriver: docker-container\n\nNodes:\nName:      mybuilder0\nEndpoint:  unix:\/\/\/var\/run\/docker.sock\nStatus:    running\nPlatforms: linux\/amd64, linux\/arm64, linux\/riscv64, linux\/ppc64le, linux\/s390x, linux\/386, linux\/arm\/v7, linux\/arm\/v6<\/code><\/pre>\n<h3>3. \u67e5\u770b\u5f53\u524d\u4f7f\u7528\u7684\u6784\u5efa\u5668\u53ca\u6784\u5efa\u5668\u652f\u6301\u7684 CPU \u67b6\u6784\uff0c\u53ef\u4ee5\u770b\u5230\u652f\u6301\u5f88\u591a CPU \u67b6\u6784\uff1a<\/h3>\n<pre><code>docker buildx ls\n\nNAME\/NODE    DRIVER\/ENDPOINT             STATUS  PLATFORMS\nmybuilder *  docker-container\n  mybuilder0 unix:\/\/\/var\/run\/docker.sock running linux\/amd64, linux\/arm64, linux\/riscv64, linux\/ppc64le, linux\/s390x, linux\/386, linux\/arm\/v7, linux\/arm\/v6\ndefault      docker\n  default    default                     running linux\/amd64, linux\/386, linux\/arm64, linux\/riscv64, linux\/ppc64le, linux\/s390x, linux\/arm\/v7, linux\/arm\/v6\n<\/code><\/pre>\n<p>\u4f7f\u7528 buildx\uff0c\u6211\u4eec\u65e0\u9700\u5bf9 Dockerfile \u8fdb\u884c\u4efb\u4f55\u4fee\u6539\uff0c\u5c31\u53ef\u4ee5\u521b\u5efa\u652f\u6301\u591a\u79cd CPU \u67b6\u6784\u7684 Docker \u955c\u50cf\uff0c\u7136\u540e\u5c06\u5176\u63a8\u9001\u5230 Docker Hub\u3002\u4efb\u4f55\u5b89\u88c5\u4e86 Docker \u7684\u7cfb\u7edf\u90fd\u53ef\u4ee5\u62c9\u53d6\u5230\u4e0e\u5b83\u7684 CPU \u67b6\u6784\u76f8\u5bf9\u5e94\u7684\u955c\u50cf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6784\u5efa\u591a\u5e73\u53f0 Docker \u955c\u50cf \u5229\u7528 Docker \u5f15\u5165\u7684\u63d2\u4ef6 buildx\uff0c\u53ef\u4ee5\u5f88\u8f7b\u677e\u5730\u6784\u5efa\u591a\u5e73\u53f0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15],"class_list":["post-372","post","type-post","status-publish","format-standard","hentry","category-docker","tag-docker"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=372"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/372\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}