Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support building multi-platform docker images #256

Merged
merged 1 commit into from
Jan 19, 2021

Conversation

MarcelWaldvogel
Copy link
Contributor

Using sudo make docker-multiarch, it is now possible to create a multi-platform docker image for i386, amd64, armv7 and arm64v8 in one go.

It is based on https://netfuture.ch/2020/05/multi-arch-docker-image-easy/, which I have been using in several projects.

Complications arose from:

  • S6-Overlay and Docker-Gen require their own architecture naming, different from each other and what Docker uses
  • Compatibility should be maintained to docker build .
  • Dockerfiles cannot easily use program-generated variables
  • Default values are broken for ARG TARGETPLATFORM (Default value on TARGETPLATFORM always overrides docker/buildx#510)
  • The nginx Docker image for linux/arm/v5 appears broken
  • archname needs to be installed early, but the rest of fs_overlay cannot be (in order to avoid installation problems later)

Therefore, architecture names and compatibility is determined by ./fs_overlay/bin/archname and S6-Overlay+Docker-Gen are fetched in RUN commands using wget. To allow backquote substitutions, they need to be run in sh -c. (This allowed for directly piping to tar, BTW.)

@SteveLTN
Copy link
Owner

Thanks!
I'll have a closer look later when I have more time.

PS. Is it possible to have Dockerhub build multiarch images?

@SteveLTN
Copy link
Owner

OK. I'll merge the PR, but wouldn't publish a new release to DockerHub until I figured a good workflow for myself.
Thanks for contributing!

@SteveLTN SteveLTN merged commit cf7175b into SteveLTN:master Jan 19, 2021
@SteveLTN
Copy link
Owner

The complication is that, now I run an ARM Mac and use docker context to connect to a remote server to do development. I hope to work out a way with the buildx.

@SteveLTN
Copy link
Owner

When trying to run on a Linux x86 machine:

=> [linux/386  8/11] RUN wget -q https://raw.githubusercontent.com/diafygi/acme-tiny/4.1.0/acme_tiny.py -O /bi  0.4s
 => [linux/386  9/11] RUN rm /etc/nginx/conf.d/default.conf                                                      0.3s
 => [linux/386 10/11] COPY ./fs_overlay /                                                                        0.1s
 => [linux/386 11/11] RUN chmod a+x /bin/*                                                                       0.9s
 => [linux/arm64  5/11] COPY ./fs_overlay/bin/archname /bin/                                                     0.2s
 => ERROR [linux/arm64  6/11] RUN sh -c "wget -q https://github.com/just-containers/s6-overlay/releases/downloa  1.9s
------
 > [linux/arm64  6/11] RUN sh -c "wget -q https://github.com/just-containers/s6-overlay/releases/download/v1.22.1.0/s6-overlay-`archname s6-overlay`.tar.gz -O -" |     tar xzC /:
#25 0.589 /bin/archname: Unsupported TARGETPLATFORM: linux/arm64
#25 1.814
#25 1.814 gzip: stdin: unexpected end of file
#25 1.849 /bin/tar: Child returned status 1
#25 1.855 /bin/tar: Error is not recoverable: exiting now
------
Dockerfile:25
--------------------
  24 |
  25 | >>> RUN sh -c "wget -q https://github.com/just-containers/s6-overlay/releases/download/$S6_OVERLAY_VERSION/s6-overlay-`archname s6-overlay`.tar.gz -O -" | \
  26 | >>>     tar xzC /
  27 |     RUN sh -c "wget -q https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/docker-gen-linux-`archname docker-gen`-$DOCKER_GEN_VERSION.tar.gz -O -" | \
--------------------
error: failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c sh -c "wget -q https://github.com/just-containers/s6-overlay/releases/download/$S6_OVERLAY_VERSION/s6-overlay-`archname s6-overlay`.tar.gz -O -" |     tar xzC /]: exit code: 2
make: *** [docker-multiarch] Error 1

Any ideas?

@MarcelWaldvogel
Copy link
Contributor Author

MarcelWaldvogel commented Jan 20, 2021

I already implied in archname that the nice things about standards are that there are so many to choose from (especially when it comes to architecture naming). Apparently, both linux/arm64 and linux/arm64/v8 seem to be used for 64-bit ARM platforms. I am treating the two as identical for now in MarcelWaldvogel/https-portal@1e94f6fb (pushes to the branch no longer show up here automatically after the merge). Could you try this out?

@MarcelWaldvogel
Copy link
Contributor Author

I just ran into the same case as well. Changing linux/arm64/v8 to linux/arm64* in the case statements (as in the commit above) fixed it for me.

  • On Ubuntu 20.04 (docker 19.03.8, buildx 0.5.1) on a Ryzen, TARGETPLATFORM is linux/arm64.
  • On Ubuntu 20.10 (docker 19.03.13, buildx 0.5.1) on i7, TARGETPLATFORM is linux/arm64/v8.

I assume docker being the cause for the difference, but have not investigated.

@SteveLTN
Copy link
Owner

Thanks for figuring this out!
I figured I could solve the problem by doing something similar to your solution, but wasn't sure if it would break the image in some other cases.

@SteveLTN
Copy link
Owner

Everything is building fine! I pushed 1.17.0.
Just made a tiny change to the Makefile, so I can separate build and pushing :-)

Thanks for you help!

@itsabdelrahman
Copy link
Contributor

Incredible work!

@MarcelWaldvogel
Copy link
Contributor Author

MarcelWaldvogel commented Jan 20, 2021

I'm glad to help. I have been using Apache for more than 20 years with an increasing number of domains and became increasingly unhappy with the amount of boilerplate needed for even just simple stuff. I am extremely happy to have found this software which gets rid of all the duplication of almost-but-not-exactly similar boilerplate, which makes it hard to keep track of the really important stuff. Now I also can use it on Raspberry Pi, and maybe even more. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants