From Docker to Podman - VS Code DevContainers
Tags: devops, docker, podman, vscode
Published: 2023-10-14 23:31:21

---
title: From Docker to Podman - VS Code DevContainers
description: Discover how to seamlessly transition from Docker to Podman for managing Visual Studio Code DevContainers, on Linux, Windows and Mac OS
published: true
date: 2023-10-12 06:58:29 UTC
tags: devops,docker,podman,vscode
canonical_url: https://blog.okikio.dev/from-docker-to-podman-vs-code-devcontainers
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kgaokci7rqtfx1dgftmd.png
---

## Been a while... 👀

It's been a minute, hasn't it? I've been...busy, but I'm back with something that I think you'll find both useful and intriguing. While I was away, I stumbled upon a nifty trick that involves swapping Docker for [Podman](https://podman.io/) in [DevContainers](https://code.visualstudio.com/docs/devcontainers/containers) on VS Code. This isn't a step-by-step guide; it's more like sharing a cool discovery I made. So, let's get to it!

![GIF from Titanic of Rose Dewitt Bukater who is now much older than when the Titanic occured, saying "It's been 84 years"](https://cdn.hashnode.com/res/hashnode/image/upload/v1697076387927/624b916f-7574-41c2-bc15-95de39e9c568.gif)

## **A Quick Refresher on DevContainers 🏝**

If you're new to the concept, DevContainers in VS Code are a way to containerize your development environment. This ensures that your setup is both portable and consistent, effectively eliminating the "it works on my machine" syndrome.

Think of DevContainers as your very own [Codespace](https://github.com/features/codespaces) or [Gitpod](https://www.gitpod.io/), but without needing the cloud. It's like having a sandbox, but your computer is the playground. You get to build your castles in an isolated space, keeping the rest of your system pristine.

## **The Podman Appeal 🎸**

Switching gears to Podman, why would you want to replace Docker? Imagine Docker as the old, reliable minivan. It gets the job done, but it's not the sleekest. Podman is like the electric car that just rolled off the assembly lineefficient, user-friendly, and secure.

Docker has been the go-to containerization tool for years, but Podman is emerging as a strong alternative. Podman offers a few advantages:

1. **Rootless Containers** : Run containers without needing root privileges, enhancing security. [Learn more about rootless containers](https://opensource.com/article/19/2/how-does-rootless-podman-work).

2. **Systemd Integration** : Better integration with Linux's init system, [systemd](https://www.freedesktop.org/wiki/Software/systemd/). For Linux users, this is a significant benefit. Podman's compatibility with [systemd](https://www.freedesktop.org/wiki/Software/systemd/) offers better process management and orchestration. [Learn more about systemd](https://www.linux.com/training-tutorials/understanding-and-using-systemd/).

3. **Follows Open Standards** : Fully compatible with [Open Container Initiative (OCI)](https://opencontainers.org/) standards. Podman is [OCI-compliant](https://opencontainers.org/), which means it adheres to industry standards for container images, making it easier to switch between different container technologies. [Learn more about OCI](https://opencontainers.org/about/overview/).

So, if you're looking to break free from Docker's grasp, Podman is worth considering.

## The Challenge: VS Code Loves Docker

Here's the hiccup: VS Code's DevContainers extension is tightly coupled with Docker. When you try to use Podman, VS Code throws a fit and keeps asking you to install Docker. That's the issue we're going to solve today.

![Image](https://media.discordapp.net/attachments/988952050345857024/1161839612466044928/CleanShot_2023-10-11_at_21.35.322x.png?ex=6539c275&is=65274d75&hm=fa14bd8f116da084ee5f64a6cc269e4e52daa74af17f4a3f153aed7fd98933f2&=&width=1314&height=1302)

## The Solution: Trick VS Code with a Shell Script

### macOS

#### **Step 1: Install Podman**

First things first, you'll need to install Podman. On a Mac, you can use [Homebrew](https://brew.sh/):

```bash
brew install podman
```

#### **Step 2: Initialize and Start Podman Machine**

Before using Podman, you need to initialize and start a Podman machine:

```bash
podman machine init
podman machine start
```

#### **Step 3: Create a Shell Script**

VS Code is looking for a command named `docker`. We'll give it what it wants, but we'll secretly redirect it to `podman`.

Create a new shell script and name it `docker`:

```bash
sudo nano /usr/local/bin/docker
```

In the script, add the following lines:

```bash
#!/bin/bash
exec podman "$@"
```

Save the file and exit the text editor.

#### **Step 4: Make the Script Executable**

Now, make the script executable:

```bash
sudo chmod +x /usr/local/bin/docker
```

#### **Step 5: Restart VS Code**

Close and reopen VS Code to apply the changes. It should now be none the wiser, happily using Podman instead of Docker.

### Linux

#### **Step 1: Install Podman**

Open your terminal and run the following command to install Podman:

```bash
sudo apt install -y podman
```

#### **Steps 2-5: Follow the same steps as for macOS**

### Windows

#### **Step 1: Install Podman for Windows**

Download and install Podman from the [official site](https://podman.io/docs/installation#windows).

#### **Step 2: Create a Batch File**

Create a batch file named `docker.bat` to act as an alias for Podman:

```batch
@echo off
podman %*
```

Place this batch file in a directory that's in your system's `PATH`.

##### **Option 1: Use an Existing Directory in** `PATH`

1. Open a Command Prompt and type `echo %PATH%` to see the directories currently in your `PATH`.

2. Choose an existing directory that you have write access to, such as `C:\Users\YourUsername\bin`.

3. Save or move your `docker.bat` file into that directory.

##### **Option 2: Create a New Directory and Add It to** `PATH`

1. Create a new directory where you want to store your batch files, for example, `C:\batch_files`.

2. Move your `docker.bat` file into this new directory.

3. To add this directory to your `PATH`, right-click on 'This PC' or 'Computer' on your desktop or File Explorer, and choose `Properties`.

4. On the left-hand side, click on `Advanced system settings`.

5. Click on the `Environment Variables` button near the bottom right.

6. Under the 'System variables' section, find and select the `Path` variable, then click on `Edit`.

7. Click on `New` and add the path to your new directory, `C:\batch_files`.

8. Click `OK` on all the dialog boxes to save your changes.

##### **Verify the Setup**

To verify that the batch file is accessible:

1. Open a new Command Prompt window (important, as existing windows won't pick up the change).

2. Type `docker` and hit Enter. If everything is set up correctly, this should now execute Podman due to the aliasing in your `docker.bat` file.

By following these steps, you ensure that the batch file is in a directory listed in your `PATH`, making it accessible from any command prompt window.

#### **Step 3: Restart VS Code**

Close and reopen VS Code to apply the changes.

## Wrapping Up

There you have ita Podman-powered DevContainer in VS Code, right on your local machine. It's like having a VIP pass to a more secure and efficient coding environment. Whether you're a newcomer or a seasoned developer, I hope you find this as useful as I did.

So go ahead, give Podman a spin, and bring a little more freedom to your containerized development environments.

Bye!

![Video gif. Two young men stand together. One holds up his fingers as if saying peace out and vanishes.](https://media0.giphy.com/media/Ru9sjtZ09XOEg/giphy.gif?cid=ecf05e47n583vcdkcv55z1ipo35ss6aq2m1n4mqsz3ia999o&ep=v1_gifs_search&rid=giphy.gif&ct=g)

---

Originally posted on [blog.okikio.dev](https://blog.okikio.dev/from-docker-to-podman-vs-code-devcontainers)