Suman Rajan

Build Your Own Raspbian Docker Image

Suman Rajan

Download Raspbian #

Download

List the partitions of the img #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
sudo fdisk -l ./2019-07-10-raspbian-buster-lite.img
[sudo] password for zoro: 
Disk ./2019-07-10-raspbian-buster-lite.img: 2 GiB, 2197815296 bytes, 4292608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x17869b7d

Device                                 Boot  Start     End Sectors  Size Id Type
./2019-07-10-raspbian-buster-lite.img1        8192  532480  524289  256M  c W95 FA
./2019-07-10-raspbian-buster-lite.img2      540672 4292607 3751936  1.8G 83 Linux

Mount the img using loop device #

1
2
3
4
sudo losetup -Pr /dev/loop0 2019-07-10-raspbian-buster-lite.img
ls /dev/loop0*
mkdir rpi
sudo mount -o ro /dev/loop0p2 ./rpi

Archive the filesystem to tarball #

1
sudo tar -C ./rpi -czpf raspbian-buster.tar.gz --numeric-owner .

And, unmount the devices

1
2
sudo umount ./rpi
sudo losetup -d /dev/loop0

Create Dockerfile #

create my Docker image

1
2
3
FROM scratch
ADD ./raspbian-buster.tar.gz /
CMD ["/bin/bash"]

Build the image #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
sudo docker build -t raspbian .

Sending build context to Docker daemon  393.5MB
Step 1/3 : FROM scratch
 ---> 
Step 2/3 : ADD ./raspbian-buster.tar.gz /
 ---> 443f05446a13
Step 3/3 : CMD ["/bin/bash"]
 ---> Running in a0b8d5392c05
Removing intermediate container a0b8d5392c05
 ---> e729ca7ffad5
Successfully built e729ca7ffad5
Successfully tagged raspbian:latest

docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
raspbian                          latest              e729ca7ffad5        12 minutes ago      947MB
raspian_buster                    latest              e729ca7ffad5        12 minutes ago      947MB

Upload to docker_hub #

Create an account in [docker hub] (https://hub.docker.com)

1
2
3
docker login
docker tag raspbian:latest raspian_buster:latest
docker push rovonovo/raspian_buster:latest
Tags: