Skip to content

Docker Alias Pattern

The Docker Alias Pattern involves creating a simplified command-line interface (CLI) wrapper for software tools by encapsulating them within [[Docker]] containers.^[600-developer__docker-run-command.md] Instead of installing a tool directly onto the host operating system, the tool is run inside a container, and a shell alias is configured to execute this complex command with a simple, native-like syntax.

Mechanics

This pattern typically requires three main steps: containerizing the application, building the image, and setting a shell alias.^[600-developer__docker-run-command.md]

  1. Container Creation: A Dockerfile is created to define the tool's environment.
  2. Image Build: The Docker image is built from the Dockerfile.
  3. Alias Configuration: A shell alias is defined to map the desired command to the docker run instruction.

For example, to run Apache Bench (ab) via Docker, one might build an image named yudady/ab and set the following alias:

bash alias ab='docker run -it yudady/ab'^[600-developer__docker-run-command.md]

This configuration allows the user to execute ab directly in the terminal, invoking the containerized version of the tool seamlessly.^[600-developer__docker-run-command.md]

Benefits

  • Isolation: Tools run in an isolated environment, preventing conflicts with host system dependencies or versions.
  • Simplified Execution: Users interact with simple commands (e.g., ab) rather than lengthy docker run strings.
  • Portability: The tool can be used across different machines (e.g., Windows, Linux) provided Docker is installed, without worrying about platform-specific installation procedures (e.g., apk, apt).
  • [[Docker]]
  • [[CLI]]
  • [[Wrapper pattern]]

Sources

^[600-developer__docker-run-command.md]