Aliasing the Docker CLI
If you remove Docker, the docker command goes with it. Your scripts, your shell history, and the many docker examples you find online all stop working, even though Podman can run most of them.
Because the Podman CLI is a drop-in replacement for most Docker commands, you can make docker run Podman instead. You then keep using the commands you already know, and your scripts continue to work without changes.
Aliasing the Docker CLI changes which program the docker command runs. It does not affect tools that connect to the Docker socket directly, such as Testcontainers or Maven. To make those tools work with Podman, enable Docker compatibility or set the DOCKER_HOST environment variable.
Prerequisites
- A running Podman machine.
- No
dockercommand on your system, or one that you want to replace. To check, runcommand -v dockeron Linux and macOS, orGet-Command dockeron Windows.
Choosing an approach
A shell alias is the quickest way to get a docker command, but it exists only inside the shell that defines it, and no other program on your system can see it. If your goal is to keep existing scripts working, do not rely on a shell alias. The other approaches put a real docker command on your PATH, so everything on your system finds it.
| Approach | Works in scripts | Survives a new terminal | Platform |
|---|---|---|---|
| Shell alias | No | Only if you edit your shell profile | Linux, macOS |
| PowerShell alias | Only in the same session | Only if you edit your PowerShell profile | Windows |
podman-docker package | Yes | Yes | Linux |
| Symbolic link | Yes | Yes | Linux, macOS |
| Wrapper script | Yes | Yes | Linux, macOS, Windows |
Creating a shell alias
Use an alias when you want a docker command in your own terminal and you do not need other programs to find it.
- Windows
- macOS
- Linux
Procedure
-
Create the alias in your current PowerShell session:
$ Set-Alias -Name docker -Value podman -
Optional: To make the alias available in every new PowerShell session, add the same command to your PowerShell profile. The profile path is stored in the
$PROFILEvariable.The profile file does not exist on a new PowerShell installation. Create the file, and the parent directory, if needed:
$ if (!(Test-Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }Add the alias to the profile:
$ Add-Content -Path $PROFILE -Value 'Set-Alias -Name docker -Value podman'Your execution policy must also allow the profile to run. The
Restrictedpolicy blocks all script files, including profiles, and is the effective policy on Windows clients when no policy is set in any scope.Check the effective policy:
$ Get-ExecutionPolicyCheck the policy for each scope:
$ Get-ExecutionPolicy -ListIf your execution policy prevents the profile from running, create a persistent
dockercommand instead.PowerShell scripts that you run from the same session can use the alias. Other programs and
cmd.exescripts cannot.
Verification
-
Check that the
dockercommand runs Podman:$ docker --helpThe output starts with the Podman description:
Manage pods, containers and images
Procedure
-
Create the alias in your current shell:
$ alias docker=podman -
Optional: To make the alias available in every new shell, add the same line to your shell profile, such as
~/.zshrc:$ echo "alias docker=podman" >> ~/.zshrcThe alias is not available to scripts that you run.
Verification
-
Check that the
dockercommand runs Podman:$ docker --helpThe output starts with the Podman description:
Manage pods, containers and images
Procedure
-
Create the alias in your current shell:
$ alias docker=podman -
Optional: To make the alias available in every new shell, add the same line to your shell profile, such as
~/.bashrc:$ echo "alias docker=podman" >> ~/.bashrcThe alias is not available to scripts that you run.
Verification
-
Check that the
dockercommand runs Podman:$ docker --helpThe output starts with the Podman description:
Manage pods, containers and images
Creating a persistent Docker command
Create a persistent docker command when you want your scripts, build tools, and other programs to find it.
- Windows
- macOS
- Linux
Procedure
-
Create the
C:\Program Files\docker\bindirectory. If you removed Docker, this directory no longer exists.$ New-Item -ItemType Directory -Force -Path 'C:\Program Files\docker\bin'Writing to
C:\Program Filesand editing the systemPATHboth require administrator permissions, so run PowerShell as an administrator. Alternatively, use a directory in your user profile and add it to your userPATH. -
Create a
C:\Program Files\docker\bin\docker.batfile with the following content:@echo offREM Delete the next line to stop showing this message.echo Emulate Docker CLI using podman. 1>&2podman %*The reminder goes to standard error, so that it does not appear in output that your scripts capture.
-
Add
C:\Program Files\docker\binto thePATHenvironment variable. -
Close all
cmdand PowerShell windows, then open a new one.Programs read the
PATHvariable when they start, so open windows do not pick up the change.
A batch file is not an executable. This affects how other programs run the docker command:
- Programs that start
dockerwithout a shell cannot rundocker.bat. Node.jsexecFile()is one example. - In a batch script, run
call docker ...rather thandocker .... Withoutcall, control does not return to your script.
Verification
-
Check that the
dockercommand runs Podman:$ docker --helpThe output starts with the reminder from the
docker.batfile:Emulate Docker CLI using podman.The rest of the output includes the Podman description:
Manage pods, containers and images -
Run a container:
$ docker run docker.io/hello-world
Procedure
The /usr/local/bin directory does not exist on all macOS installations. Create it if needed:
$ sudo mkdir -p /usr/local/bin
Then perform one of the following steps:
-
Link the
podmanexecutable to/usr/local/bin/docker:$ sudo ln -s $(command -v podman) /usr/local/bin/dockerThis is the shortest option. The Podman installer places the executable in
/opt/podman/bin/podman, andcommand -valso finds it if you installed Podman another way, such as with Homebrew. -
Create a
/usr/local/bin/dockerscript with the following content:#!/bin/sh[ -e /etc/containers/nodocker ] || \echo "Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg." >&2exec podman "$@"Then make the script executable:
$ sudo chmod +x /usr/local/bin/dockerThe script reminds you that Podman is running the command. To stop the reminder, create an empty
/etc/containers/nodockerfile:$ sudo touch /etc/containers/nodockerThe script prints the reminder, not Podman. A symbolic link never prints it, and
/etc/containers/nodockerhas no effect on one.
If you reinstall Docker Desktop, it can overwrite or shadow /usr/local/bin/docker. Run command -v docker to find out which docker command your system uses.
Verification
-
Check that the
dockercommand runs Podman:$ docker --helpIf you created the wrapper script, the output starts with the
Emulate Docker CLI using podman.reminder. In both cases, the output includes the Podman description:Manage pods, containers and images -
Run a container:
$ docker run docker.io/hello-world
Procedure
Perform one of the following steps:
-
Install the
podman-dockerpackage, which provides adockercommand and the Docker manual pages:$ sudo dnf install podman-dockerOn Debian and Ubuntu, run
sudo apt install podman-docker.Prefer this option where your distribution provides the package. It installs the same wrapper script as the following options, and your package manager keeps it up to date. The package reminds you that Podman is running the command. To stop the reminder, create an empty
/etc/containers/nodockerfile:$ sudo touch /etc/containers/nodocker
Use one of the following options if your distribution does not provide the podman-docker package. Both options write to /usr/local/bin, so create that directory if it does not exist:
$ sudo mkdir -p /usr/local/bin
-
Link the
podmanexecutable to/usr/local/bin/docker:$ sudo ln -s $(command -v podman) /usr/local/bin/dockerThis is the shortest option.
-
Create a
/usr/local/bin/dockerscript with the following content:#!/bin/sh[ -e /etc/containers/nodocker ] || \echo "Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg." >&2exec podman "$@"Then make the script executable:
$ sudo chmod +x /usr/local/bin/dockerThe script reminds you that Podman is running the command. To stop the reminder, create an empty
/etc/containers/nodockerfile:$ sudo touch /etc/containers/nodockerThe script prints the reminder, not Podman. A symbolic link never prints it, and
/etc/containers/nodockerhas no effect on one.
Verification
-
Check that the
dockercommand runs Podman:$ docker --helpIf you created the wrapper script, the output starts with the
Emulate Docker CLI using podman.reminder. In both cases, the output includes the Podman description:Manage pods, containers and images -
Run a container:
$ docker run docker.io/hello-world
Podman supports most Docker commands, but not all of them behave identically. If a command does not work as you expect, see the Podman documentation.