Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).

How I built the first ARM-based Docker Image on Pinebook using buildx tool?

4 min read

The Pinebook Pro is a Linux and *BSD ARM laptop from PINE64. It is built to be a compelling alternative to mid-ranged Chromebooks that people convert into Linux laptops. It features an IPS 1080p 14″ LCD panel, a premium magnesium alloy shell, high capacity eMMC storage, a 10,000 mAh capacity battery, and the modularity that only an open-source project can deliver.

The Pinebook Pro comes with Manjaro Linux pre-installed. Manjaro is, effectively, Arch Linux but with a set of reasonably sane defaults—” real” Arch might be considered more of a framework upon which to hang a distro, rather than a complete distribution itself. If you’re not into Manjaro, that’s fine—the Pine64 project offers a wide selection of additional, downloadable user-installable Pinebook Pro images including Debian, Fedora, NetBSD, Chromium OS, and more.

Many different Operating Systems (OS) are freely available from the open-source community and partner projects. These include various flavors of Linux (Ubuntu, Debian, Manjaro, etc.) and *BSD. Under ‘Pinebook Pro Software Release/OS Image Download Section’ you will find a complete list of currently supported Operating System images that work with the Pinebook as well as other related software.

Let us verify the architecture of Pinebook Pro Linux system via lscpu command:

$ sudo lscpu
Architecture:                    aarch64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
CPU(s):                          6
On-line CPU(s) list:             0-5
Thread(s) per core:              1
Core(s) per socket:              3
Socket(s):                       2
Vendor ID:                       ARM
Model:                           4
Model name:                      Cortex-A53
Stepping:                        r0p4
CPU max MHz:                     1800.0000
CPU min MHz:                     408.0000
BogoMIPS:                        48.00
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1:        Mitigation; __user pointer sanitization
Vulnerability Spectre v2:        Vulnerable
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected
Flags:                           fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid

Installing Docker on Manjaro-ARM OS running on Pine64

Docker doesn’t come with Pine64 Pro Laptop by default but you can install it flawlessly following the below steps:

ssh ajeetraina@192.168.1.8
ajeetraina@192.168.1.8's password: 
Welcome to Manjaro-ARM
~~Website: https://manjaro.org
~~Forum:   https://forum.manjaro.org/c/manjaro-arm
~~IRC:     #manjaro-arm on irc.freenode.net
~~Matrix:  #manjaro-arm-public:matrix.org
Last login: Mon Oct  5 09:17:42 2020

Keeping Manjaro ARM Repository up-to-date

 sudo pacman -Syu

Installing Docker 20.10.3

pacman -S docker

Running Docker Service

systemctl start docker.service
systemctl enable docker.service

Verifying Docker



[ajeetraina@pine64 ~]$ sudo docker version
[sudo] password for ajeetraina: 
Client:
 Version:           20.10.3
 API version:       1.40
 Go version:        go1.15.8
 Git commit:        48d30b5b32
 Built:             Sun Feb 21 21:20:17 2021
 OS/Arch:           linux/arm64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          19.03.12-ce
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.14.5
  Git commit:       48a66213fe
  Built:            Sat Jul 18 02:39:40 2020
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          v1.4.1.m
  GitCommit:        c623d1b36f09f8ef6536a057bd658b3aa8632828.m
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Installing Docker Compose

sudo pacman -S docker-compose
[ajeetraina@pine64 ~]$ sudo pacman -S docker-compose
warning: docker-compose-1.28.4-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Packages (1) docker-compose-1.28.4-1

Total Installed Size:  1.08 MiB
Net Upgrade Size:      0.00 MiB

:: Proceed with installation? [Y/n] Y
(1/1) checking keys in keyring                                                                           [##############################################################] 100%
(1/1) checking package integrity                                                                         [##############################################################] 100%
(1/1) loading package files                                                                              [##############################################################] 100%
(1/1) checking for file conflicts                                                                        [##############################################################] 100%
(1/1) checking available disk space                                                                      [##############################################################] 100%
:: Processing package changes...
(1/1) reinstalling docker-compose                                                                        [##############################################################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...
[ajeetraina@pine64 ~]$ sudo docker-compose version
docker-compose version 1.28.4, build unknown
docker-py version: 4.4.4
CPython version: 3.9.2
OpenSSL version: OpenSSL 1.1.1j  16 Feb 2021

Running ARM-based Docker Images on Pinebook (64bit)

sudo docker run --rm arm64v8/alpine uname -a
Unable to find image 'arm64v8/alpine:latest' locally
latest: Pulling from arm64v8/alpine
069a56d6d07f: Pull complete 
Digest: sha256:c45a1db6e04b73aad9e06b08f2de11ce8e92d894141b2e801615fa7a8f68314a
Status: Downloaded newer image for arm64v8/alpine:latest
Linux 216b7a576112 5.7.19-1-MANJARO-ARM #1 SMP Wed Sep 2 20:43:09 +03 2020 aarch64 Linux
[ajeetraina@pine64 test]$ 

Running ARM-based Docker Images on Pinebook (32bit)

 sudo docker run --rm arm32v7/alpine uname -a
Unable to find image 'arm32v7/alpine:latest' locally
latest: Pulling from arm32v7/alpine
f55b840e27d3: Pull complete 
Digest: sha256:db5f021b29ec8fcf605f00d2aac06345756b0ffbdea0e7994044fe9172619a0a
Status: Downloaded newer image for arm32v7/alpine:latest
Linux 8c9b1e93f0d9 5.7.19-1-MANJARO-ARM #1 SMP Wed Sep 2 20:43:09 +03 2020 aarch64 Linux
[ajeetraina@pine64 test]$ 

Building Docker Image using buildx

Docker Buildx is a CLI plugin that extends the docker command with the full support of the features provided by Moby BuildKit builder toolkit. It provides the same user experience as docker build with many new features like creating scoped builder instances and building against multiple nodes concurrently.

Docker Buildx is included in Docker 19.03+. BuildKit is designed to work well for building for multiple platforms and not only for the architecture and operating system that the user invoking the build happens to run. When you invoke a build, you can set the --platform flag to specify the target platform for the build output, (for example, linux/amd64, linux/arm64, darwin/amd64).

[ajeetraina@pine64 ~]$ sudo docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS  PLATFORMS
default * docker                  
  default default         running linux/arm64, linux/arm/v7, linux/arm/v6
[ajeetraina@pine64 ~]$ 

We are currently using the default builder, which is basically the old builder.  Let’s create a new builder, which gives us access to some new multi-arch features.

[ajeetraina@pine64 ~]$ sudo docker buildx create --name mybuilder
mybuilder

To switch between different builders use docker buildx use <name>. After running this command, the build commands will automatically use this builder.

[ajeetraina@pine64 ~]$ sudo docker buildx use mybuilder
[ajeetraina@pine64 ~]$ sudo docker buildx ls
NAME/NODE    DRIVER/ENDPOINT             STATUS   PLATFORMS
mybuilder *  docker-container                     
  mybuilder0 unix:///var/run/docker.sock inactive 
default      docker                               
  default    default                     running  linux/arm64, linux/arm/v7, linux/arm/v6
[ajeetraina@pine64 ~]$ 

Here I created a new builder instance with the name mybuilder, switched to it, and inspected it.  Note that --bootstrap isn’t needed, it just starts the build container immediately.  Next we will test the workflow, making sure we can build, push, and run multi-arch images.

[ajeetraina@pine64 ~]$ sudo docker buildx inspect --bootstrap
[+] Building 70.8s (1/1) FINISHED                                                                                                                                             
 => [internal] booting buildkit                                                                                                                                         70.8s
 => => pulling image moby/buildkit:buildx-stable-1                                                                                                                      67.7s
 => => creating container buildx_buildkit_mybuilder0                                                                                                                     3.1s
Name:   mybuilder
Driver: docker-container

Nodes:
Name:      mybuilder0
Endpoint:  unix:///var/run/docker.sock
Status:    running
Platforms: linux/arm64, linux/arm/v7, linux/arm/v6
[ajeetraina@pine64 ~]$

Let’s create a simple example Dockerfile, build a couple of image variants, and push them to Hub.

mkdir test && cd test && cat <<EOF > Dockerfile
FROM ubuntu
RUN apt-get update && apt-get install -y curl
WORKDIR /src
COPY . .
EOF

Finally, we are all set to build our first ARM-based Docker image using buildx tool.


[ajeetraina@pine64 test]$ sudo docker buildx build --platform linux/arm64 -t ajeetraina/pinedemo:latest --push .
[+] Building 67.5s (7/7) FINISHED                                                                                                                                             
 => [internal] load build definition from Dockerfile                                                                                                                     0.1s
 => => transferring dockerfile: 31B                                                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                          0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                         1.2s
 => [1/2] FROM docker.io/library/ubuntu@sha256:703218c0465075f4425e58fac086e09e1de5c340b12976ab9eb8ad26615c3715                                                          0.1s
 => => resolve docker.io/library/ubuntu@sha256:703218c0465075f4425e58fac086e09e1de5c340b12976ab9eb8ad26615c3715                                                          0.0s
 => CACHED [2/2] RUN apt-get -y update && apt-get install -y curl                                                                                                        0.0s
 => exporting to image                                                                                                                                                  65.9s
 => => exporting layers                                                                                                                                                 11.3s
 => => exporting manifest sha256:2790ff98adad1108fdeb51ff19cca417add8d800036e6fa5d270756eec8ab716                                                                        0.0s
 => => exporting config sha256:703a952f9c0b9447cc0a6ddcd3e4669b009c6367238c9ae6bd5609174dd45cb0                                                                          0.0s
 => => pushing layers                                                                                                                                                   53.8s
 => => pushing manifest for docker.io/ajeetraina/pinedemo:latest                                                                                                         0.7s
 => [auth] ajeetraina/pinedemo:pull,push token for registry-1.docker.io                                                                                                  0.0s
[ajeetraina@pine64 test]$

Congratulations! You just created your first ARM-based Docker Image over Pinebook Pro Linux laptop and pushed it to DockerHub.

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).
Join our Discord Server
Index