Docker is fun but platform incompatibility is not
So the other day I wanted to run some tests on Chrome using Selenium (for my research project). This requires downloading this tool called ChromeDriver. But if you go to ChromeDriver’s official site and click on the download link, you’ll realize that the tool is literally a pure executable and nothing more. No README or file structure or anything. Apple quarantines new executables by default so that you have to give explicit execution permission, and that reminded me of how sketchy it is to just run a random executable you downloaded from the internet. I decided to do this the morally correct way and attempt to learn how to use Docker as quickly as possible so that I can run my tests in a Docker container.
Here’s some official Docker artwork to lighten the mood!
Docker is a pretty powerful tool. I was already interested in Docker after learning about it from YouTube, and I immediately took the chance to use it for an actual project. You can read about it here, but the basic idea of a Docker container is the following: it’s like a virtual machine, in that it contains an entire environment separate from the host environment, except that it directly uses the OS of the host system rather than running an entire OS on top of the host OS. This makes Docker containers significantly lighter and easier to use than virtual machines.
In order to create a new Docker container, you start from a Docker image, which is a condensed version of the desired environment. Example: this is the official Node image, and if you just want the barebones you can take the node:[version]-alpine image, which is installed on Alpine, one of the lightest Linux distros. Then you can run additional commands to set up what you need in the container, which you store in the Dockerfile
.
As I suspected, people do Selenium testing in Docker containers all the time, so I thought this was going to be straightforward. I took the Chrome image from docker-selenium, but it gave me a platform incompatibility warning when I ran it (image was built on amd64
but my computer is arm64
). I couldn’t figure out how to fix this at first so I just ignored it. The container seemed to be working, but whenever I tried to run tests, I’d get errors saying that Chrome or ChromeDriver mysteriously crashed. I spent a while trying to add options such as --disable-dev-shm-usage
, but nothing seemed to work. I could have been close to a solution, but I have no way of knowing.
Eventually, after a fair amount of internet sleuthing, I figured out that the platform incompatibility error wasn’t just a me issue; there’s an entire open issue on the GitHub whose exact purpose is to build a Selenium image on arm
. By some stroke of luck @jamesmortensen had recently developed the Selenium image I needed (they are all on this DockerHub page). But when I set up the container and tried to run tests, the program just appeared to hang. I think I could have figured this one out, but I decided that at this point, it would be more worth it to just run ChromeDriver on my personal Chrome app and worry about this later.
It would be interesting to use Docker to emulate a Linux distro and poke around a bit. Realistically, though, I think I will just be using it to more easily configure large software projects in the future (or to run tests that I don’t want messing with my computer).
Further reading:
- Docker docs
- Fireship YouTube channel, from which I’ve actually learned a lot about software development in general, though particularly web development
- This blog post about running untrusted code in a secure Docker container might be of some use; I haven’t read it in detail yet.