Building Docker Images With GitlabCI on a Raspberry Pi Model B

What will I learn from this?

How to use a Raspberry Pi Model B as a GitlabCI runner building docker images. Docker didn’t work for me until I rolled back to the previous version. Story at the bottom of the post.

Requirements

  • 1x Raspberry Pi 1 Model B (512mb 2 USB ports) running Raspbian Stretch Lite 4.14
  • Keyboard with c, v and ctrl keys

Disclaimer

This is what I got to after about 8 hours of fucking around. I have tested this on two different Model B’s and it all worked fine, but I don’t know why I couldn’t get the latest version of Docker working on my 3. If these steps don’t work for you I’d love to know what the problem you’re having is, so please contact me! I will help you as best as I can!

Code

Install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Install Docker.
# https://docs.docker.com/install/linux/docker-ce/debian/#install-using-the-convenience-script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo apt-get update

# Downgrade to the previous version.
sudo apt-get install docker-ce=18.06.1~ce~3-0~raspbian

# Clean up after the downgrade.
sudo apt autoremove

# Install Gitlab Runner.
sudo apt-get install gitlab-runner

# Add users to docker group.
sudo usermod -aG docker <your user>
sudo usermod -aG docker gitlab-runner

Restart Session

You need a new session for the first usermod change to come into affect so open a new terminal window or disconnect/reconnect if you’re doing this over SSH.

Check and Configure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Make sure Docker works.
# If you get a permissions issue its probably due to setting the wrong user above, or not restarting your session.
docker info

# Make sure docker images can connect to the internet.
# You should get some output with IP addresses.
docker run alpine nslookup www.google.com

# Register your runner.
# https://docs.gitlab.com/runner/commands/#interactive-registration
# You most likely want a shell executor.
# https://docs.gitlab.com/ce/ci/docker/using_docker_build.html#use-shell-executor
sudo gitlab-runner register

# Ensure Docker and Gitlab Runner services are running.
systemctl status docker
systemctl status gitlab-runner

You should now have a gitlab runner that can build docker images, and it should all keep on running if you restart your Pi.

Backstory

I tried for ages to get Docker running properly on my Raspberry Pi 3. For some reason Docker containers were completely unable to connect to the internet. The host could just fine but any Docker containers weren’t interested at all. I Googled things and read forum threads and pasted commands to no avail. After a while I tried everything out on one of my old Model B’s and I got a bit further but things still didn’t work correctly until I downgraded Docker to a previous version. After that everything worked perfectly. I only went back one version but a lot of dependencies were removed so I’m guessing something big changed.

I tried the downgrade on my 3 and got nowhere, possibly due to the rampant command pasting mentioned above. There’s a good chance that if I wiped it and installed raspbian-lite and followed the steps above then everything would work perfectly, but if I can use my Model B instead of my 3 for this then I can save the 3 for something more demanding.