Docker woes with Raspberry Pi

This started off as a post describing a very frustrating problem I was having deploying an app to a Raspberry Pi running on my LAN, but in the process of writing it, I solved the problem, only to be smacked straight in the forehead with a new, much-less-solvable problem.

So, I have a project I’ve been picking at, on and off, to move this blog to my very own self-hosted Django app. As a person who knows (or knew) basically nothing about web development, this has been an interesting time! Other than Python, I’m having to pick up basically everything from scratch: PostgerSQL, HTML, CSS, remote hosting, APIs, containers, servers, proxy servers, and (OMINOUS FORESHADOWING) CPU architecture.

Django is a powerful framework, but as such, it is WILDLY complicated, and that by itself has taken me some time to get my head around it. As a first stab, I am building a very, **very** basic micro-blogging site I’m calling tinyblog. The plan is: 1) start simple, with just posts and and landing page, 2) deploy to a test server on my local network, 3) deploy to a VM with a public-facing IP, and 4) add features and update production as I go.

Part 1 is going fine. I don’t like to do things without a grasp of what is happening under the hood, so using Django has been slow, but I now have a functioning app with a few models, two views to pull the posts, and two templates to display them. OK.

Part 2, I hit a snag. The plan was to use an old RaspberryPi 3 I have sitting around as the test server. I would package the app, the PostgreSQL database, and the reverse proxy in different Docker containers and network them together.

What happened instead was that Docker got… weird.

I would SSH into the RaspberryPi, set up the Docker network,1 then spin up containers from the images I’d scp’d over from my desktop. But they couldn’t connect to the Docker network I’d just set up (??) and when I removed them and tried again, I couldn’t even spin them up again because it said the container names were already in use (????), even though docker ps -a showed *nothing** (???????).

I pruned the system, I pruned the networks, I pruned the volumes, I restarted Docker, the f*&%ing thing kept f%&$ing not f@¿%ing working.

But reading through various tangentially-related StackOverflow stemwinders, something had stuck in my head: “namespace,” and as I walked my dog, I kept chewing this over. Namespace.

Ah, that’s it. F&%$ me.

So when you install Docker, it tells you to add your Linux username to the docker group so you can run Docker commands as root. What it **doesn’t** tell you is that Docker does not have system privileges to bind ports below 1024. So when I was trying to run a Docker container that binds port 80, I would get an “access denied, you don’t have privileges” error, and I would just add a “sudo” to my command, as one does. And it worked.

The problem is, I was creating two different sets of assets (both containers and networks) in two different name spaces: one for rootuser and one for peter. When I ran docker ps -a as peter, it showed nothing, because I was creating my containers in the rootuser namespace. Likewise, when I tried to add one of my rootuser containers to the Docker network I created as peter, I got a “network not found” error, because the network was in a different namespace.

Problem solved, but unfortunately I am still boned with this particular project.

As you may have guessed by now, Docker images built on an x86_64 architecture don’t run on Raspberry Pi’s ARM64 architecture, so **sad trombone** for me, the RaspberryPi is cooked. Off to pull an old laptop out of a closet and slap Ubuntu Server on it.

  1. Yeah yeah yeah, use Docker Compose, I will. OK? ↩︎

One response to “Docker woes with Raspberry Pi”

  1. […] not much, but it’s mine. After struggling a bit with Docker in the testing environment, I managed to get everything running on an old laptop, and it worked great! Moving the app to […]

Leave a Reply

Your email address will not be published. Required fields are marked *