Moving from Docker to Podman for local development

Previously, I wrote a short article about how I work without docker-compose. While it’s somewhat crucial software for my workload, I realized I could achieve the basic functionality with less code in my environment.

The old article only used a PostgreSQL container in the system, which was fairly boring. Now that I’ve been using more Jupyter notebooks, I wanted to share this snippet with you. This code provides the bare minimum functionality of docker-compose, but it’s simple to run and work with.

VAGRANTFILE_API_VERSION = "2" if not defined? VAGRANTFILE_API_VERSION

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "debian/testing64"

  config.vm.network :private_network, ip: "192.168.33.12"

  config.vm.provider :libvirt do |guest|
    guest.memory = 2048
  end

  config.vm.provision :shell, inline: <<-SHELL
    apt-get update
    apt-get install -y podman zstd

    podman network create potato_network
  SHELL

  config.vm.provision :podman do |container|
    container.run "postgres", image: "docker.io/library/postgres:16", args: %w[
      --env POSTGRES_USER=potato
      --env POSTGRES_PASSWORD=potato
      --env POSTGRES_DB=potato_development
      --network potato_network
    ].join(" ")

    container.run "jupyter", image: "quay.io/jupyter/scipy-notebook:python-3.11", args: %w[
      --volume "/vagrant:/home/jovyan/work"
      --publish 10000:8888
      --network potato_network
    ].join(" ")
  end
end

I should add a warning: this script will not run properly the second time you provision. This is mainly because of how Podman handles network adapter creation. You could write an additional if statement with podman network exists, but I’ve found that simply running vagrant provision --provision-with podman is much easier for my workload.

I also set a private IP address for this virtual machine that libvirt manages on the Debian host.

Comments

Leave a Reply

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