Put it all in a box
Two things recently gave me motivation to look into containers for development.
First, the supply chain attacks that keep happening have made me hesitant to install random package/plugin directly on my machine. Second, flatpaks are OCI compliant. The fact that flatpaks are just fancy “Docker Containers” has changed my view on what containers are for. They can be more than just the box that makes the server understand my code. They can be a collection of all the things I need to work on a specific project.
After a bit of struggling, it ended up being quite easy: The container provides an ide and runs the code, while the source code stays on the host. Then you just have to wire it up correctly.
In the Container …
goes all the things you need to work on the project. Basic tools: python, lsp, a code editor and some config. On top of that you install the project itself.
Wiring it up correctly
This setup is a two way street: you, the developer on the host, need to be able to use the editor in the container. And the editor in the container needs to be able to edit source files on the host.
The second part is solved rather easily. When running the container you mount the source directory on the host into a generic project directory of the container. Assuming you do so from the source directory, you run podman with
-v .:/home/non_root/project
Accessing the editor in the container from the host, depends on the specific editor you use.
For code-server, a VS Code in a web-browser project, you tell the container to expose port 8080, tell the editor to bind to that port and connect container and host ports by using the -p 8080:8080 flag when running. Once the container is running, go to your web-browser and then to localhost on port 8080.
For emacs, you setup the wayland socket in the container
RUN mkdir /tmp/krabby_patty
ENV XDG_RUNTIME_DIR=/tmp/krabby_patty
ENV WAYLAND_DISPLAY=spongebob
Then simply mount that socket to the host wayland socket via -v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/tmp/krabby_patty/spongebob. For some extra permissions, you also have to add the --userns=keep-id flag. (Honestly, I don’t quite understand why.)
A complete example can be found in my knapsack solver project under “Develop in a Container”.