Use Podman with Visual Studio Code Docker Extension

Guillem Riera
2 min readMar 17, 2023

--

mac computer with a developer IDE
Photo by Clément Hélardot on Unsplash

One colleague that switched to Podman recently asked me if it is possible to use it with Visual Studio Code’s Docker extension.

Out of the box it did not detect the presence of Podman’s Socket, which by the way, is compatible with the Docker CLI and hence also compatible with VS Code.

We solved this configuring the DOCKER_HOST variable in the extension.

I will provide a script to automate the config in macOS, but you can do the same manually on other systems as it will also work:

  1. Close VS Code
  2. Start Podman
  3. Configure VS Code this way (using the terminal):
# Make a backup of the current VS Code Config:
cp $HOME/Library/Application\ Support/Code/User/settings.json settings.json

# Find out the name of your Podman Machine, this is straightforward:
PODMAN_MACHINE_NAME=$(podman machine list -q --format '{{.Name}}' | grep '*' | tr -d '*')

# Get the location of the Socket
PODMAN_SOCKET=$(podman machine inspect ${PODMAN_MACHINE_NAME} | jq -r '.[].ConnectionInfo.PodmanSocket.Path')
# if you want to know where the socket is for later:
# echo $PODMAN_SOCKET

# Make a connection string with the unix:// prefix:
PODMAN_HOST="unix://${PODMAN_SOCKET}"

# [Dry-Run] Add the configuration to the settings.json VS Code file:
jq --arg PODMAN_HOST "${PODMAN_HOST}" '. + {"docker.environment":{DOCKER_HOST:$PODMAN_HOST}}' settings.json

# Once it looks good, override the config:
jq --arg PODMAN_HOST "${PODMAN_HOST}" '. + {"docker.environment":{DOCKER_HOST:$PODMAN_HOST}}' settings.json > $HOME/Library/Application\ Support/Code/User/settings.json settings.json

If you prefer to configure this on the UI, just use the value of $PODMAN_HOST obtained before as DOCKER_HOST variable under the Docker:Environment section:

Item:

DOCKER_HOST

Value:

unix:///Users/YOUR_USER_HERE/.local/share/containers/podman/machine/YOUR_MACHINE_HERE/podman.sock

Enjoy!

P.S: want to know how to make devcontainer work properly on rootless Podman? The solution is here: https://medium.com/@guillem.riera/making-visual-studio-code-devcontainer-work-properly-on-rootless-podman-8d9ddc368b30

--

--

Guillem Riera

Principal Technical Consultant, DevOps, CICD Architect