The issue you're encountering is that shell aliases are not automatically available in scripts. When you define an alias in your interactive shell session (alias docker='podman'), it only works in that specific shell session and its child processes, but not in separate script executions.
Why it doesn't work:
- Aliases are shell-specific: They are not inherited by scripts unless explicitly sourced.
- Scripts run in a new shell: When you execute
./build-docker-image.sh, it runs in a new shell environment that doesn't know about your aliases.
Solutions:
1. Define the alias inside the script
Add the alias definition at the top of your script:
#!/bin/bash
alias docker='podman'
# Rest of your script...
2. Use a function instead of an alias
Functions are more portable and work in scripts:
#!/bin/bash
docker() {
podman "$@"
}
# Rest of your script...
3. Use the full command directly in the script
Replace docker with podman in your script:
#!/bin/bash
# Instead of: docker build ...
podman build ...
4. Source your shell configuration
If you have the alias in your ~/.bashrc or similar, you can source it:
#!/bin/bash
source ~/.bashrc
# Now the alias should work
5. Use environment variables (less common)
You could set an environment variable and check for it:
#!/bin/bash
DOCKER_CMD=${DOCKER_CMD:-docker}
$DOCKER_CMD build ...
Then run it with:
DOCKER_CMD=podman ./build-docker-image.sh
Best Practice:
The most straightforward and maintainable solution is to either:
- Replace
docker with podman directly in your script, or
- Use a function definition at the top of your script if you need to maintain compatibility with both commands.
This makes your script more portable and predictable across different environments.