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 in DevContainers 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!
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 or Gitpod, 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.
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 line efficient, 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:
So, if you're looking to break free from Docker's grasp, Podman is worth considering.
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.
First things first, you'll need to install Podman. On a Mac, you can use Homebrew:
brew install podman
Before using Podman, you need to initialize and start a Podman machine:
podman machine init
podman machine start
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
:
sudo nano /usr/local/bin/docker
In the script, add the following lines:
#!/bin/bash
exec podman "$@"
Save the file and exit the text editor.
Now, make the script executable:
sudo chmod +x /usr/local/bin/docker
Close and reopen VS Code to apply the changes. It should now be none the wiser, happily using Podman instead of Docker.
Open your terminal and run the following command to install Podman:
sudo apt install -y podman
Download and install Podman from the official site.
Create a batch file named docker.bat
to act as an alias for Podman:
@echo off
podman %*
Place this batch file in a directory that's in your system's PATH
.
PATH
echo %PATH%
to see the directories currently in your PATH
.C:\Users\YourUsername\bin
.docker.bat
file into that directory.PATH
C:\batch_files
.docker.bat
file into this new directory.PATH
, right-click on 'This PC' or 'Computer' on your desktop or File Explorer, and choose Properties
.Advanced system settings
.Environment Variables
button near the bottom right.Path
variable, then click on Edit
.New
and add the path to your new directory, C:\batch_files
.OK
on all the dialog boxes to save your changes.To verify that the batch file is accessible:
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.
Close and reopen VS Code to apply the changes.
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!
Also published here.