{"id":2053,"date":"2021-04-28T17:42:27","date_gmt":"2021-04-28T17:42:27","guid":{"rendered":"https:\/\/bitcows.com\/?p=2053"},"modified":"2024-05-10T18:04:41","modified_gmt":"2024-05-10T18:04:41","slug":"how-to-deploy-docker-images-built-on-m1-macs-with-apple-silicon","status":"publish","type":"post","link":"https:\/\/bitcows.com\/?p=2053","title":{"rendered":"How to Deploy Docker Images Built on M1 Macs With Apple Silicon"},"content":{"rendered":"<p>I just bought my new M1 Apple Silicon Mac Mini, and after about a week of using it I ran into an issue related to different architectures and deployment of Docker containers. I can build and run images on my M1 Mac fine, but when I try and push the image built on the Apple Silicon Mac to a cloud server running Linux distro, I see the following error:<br \/>\n<code>standard_init_linux.go:211: exec user process caused \"exec format error\"<\/code><\/p>\n<p>This was troubling to say the least. So for awhile I just used my old AMD64 Mac to compile and push my containers. But this is not ideal, so how can we fix this?<\/p>\n<h3>\n<a href=\"https:\/\/docs.docker.com\/docker-for-mac\/apple-silicon\/\" rel=\"noopener noreferrer\" target=\"_blank\">System requirements<\/a><br \/>\n<\/h3>\n<p>You must install Rosetta 2 as some binaries are still Darwin\/AMD64. To install Rosetta 2 manually from the command line, run the following command:<br \/>\n<code>softwareupdate --install-rosetta<\/code><\/p>\n<h3>\nUsing buildx<br \/>\n<\/h3>\n<p><a href=\"https:\/\/docs.docker.com\/buildx\/working-with-buildx\/\" rel=\"noopener noreferrer\" target=\"_blank\">Buildx<\/a> comes with a default builder that you can see by typing <code>docker buildx ls<\/code> into your terminal. However, we want to make and use a builder ourselves.<\/p>\n<h3>Make a builder<\/h3>\n<p>You will need a new builder, to make one use <code>docker buildx create --name m1_builder<\/code>. Now you should see the new builder when running <code>docker buildx ls<\/code>.<\/p>\n<h3>\nBootstrap the Builder<br \/>\n<\/h3>\n<p>The next steps are to use the new builder then bootstrap it. To allow docker to use new builder run, <code>docker buildx use m1_builder<\/code> and then <code>docker buildx inspect --bootstrap<\/code>, which will inspect and bootstrap the builder instance you&#8217;re using.<\/p>\n<h3>\nBuild with the builder<br \/>\n<\/h3>\n<p>Now, navigate to where you want to build and push an image so you can run this pseudo-command:<br \/>\n<code>docker buildx build --platform linux\/amd64,linux\/arm64,linux\/arm\/v7 --tag &lt;remote image repository&gt; --push .\/<\/code><\/p>\n<h3>\nView Manifest<br \/>\n<\/h3>\n<p>Once your image has been built and pushed, you can inspect the manifest by running: <code>docker buildx imagetools inspect &lt;remote image repository&gt;<\/code><br \/>\nYou should see a manifest printout with all your different architectures. <\/p>\n<h3>\nClean up<br \/>\n<\/h3>\n<p>Finally, to clean up any extra disk space usage you can run <code>docker buildx prune --all<\/code> to reduce the Docker footprint.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just bought my new M1 Apple Silicon Mac Mini, and after about a week of using it I ran into an issue related to different architectures and deployment of Docker containers. I can build and run images on my M1 Mac fine, but when I try and push the image built on the Apple&hellip;<\/p>\n<p class=\"more-link\"><a href=\"https:\/\/bitcows.com\/?p=2053\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":2294,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-2053","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-basicinfo"],"_links":{"self":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/2053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2053"}],"version-history":[{"count":1,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/2053\/revisions"}],"predecessor-version":[{"id":2276,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/2053\/revisions\/2276"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/media\/2294"}],"wp:attachment":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}