Moving from Docker to Podman for local development

published on | edited on

Previously, I wrote a short article of how I work without docker-compose. It is somewhat crucial software for my workload, but at the same time, I realized that I could achieve the basic functionality with little less code in my environment.

The old article only used PostgreSQL container in the system, and therefore, it was boring. Now, I have been using more and more Jupyter notebooks, I wanted to share this snippet with you all. This code does bare minimum of docker-compose or podman-compose, but it is fairly 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 would like to add a warning in here because this script will not run second time you provision. Mainly, that is because of network adapter creation with Podman. You can write additional if statement with podman network exist, but I found it just running vagrant provision --with-provider podman is a lot easier to work with for my workload.

I also have a private IP address for this virtual machine that is managed with libvirt on Debian host.