有用的 Docker shell 别名可以加速开发

2025-06-07

有用的 Docker shell 别名可以加速开发

我一直都在使用 Docker。放弃 MAMP 栈转而使用 Docker 是我做过的最便捷、最实用的决定之一。如果你对 Docker 感兴趣,可以看看我目前的
Docker Stack,里面介绍了我如何使用 Docker 开发
PHP 项目。

有用的 Shell 别名

如果您使用 Docker,则需要执行大量 shell 命令来启动、停止和管理容器。大多数命令通常针对 Docker Compose,它是 Docker 的管理层。为了改进 shell 的使用,我创建了几个别名,以减少执行最常见操作所需的输入量。

容器管理

# Start the docker-compose stack in the current directory
alias dcu="docker-compose up -d"

# Start the docker-compose stack in the current directory and rebuild the images
alias dcub="docker-compose up -d --build"

# Stop, delete (down) or restart the docker-compose stack in the current directory
alias dcs="docker-compose stop"
alias dcd="docker-compose down"
alias dcr="docker-compose restart"

# Show the logs for the docker-compose stack in the current directory
# May be extended with the service name to get service-specific logs, like
# 'dcl php' to get the logs of the php container
alias dcl="docker-compose logs"

# Quickly run the docker exec command like this: 'dex container-name bash'
alias dex="docker exec -it"
Enter fullscreen mode Exit fullscreen mode

全系统管理

# 'docker ps' displays the currently running containers
alias dps="docker ps"

# This command is a neat shell pipeline to stop all running containers no matter
# where you are and without knowing any container names
alias dsa="docker ps -q | awk '{print $1}' | xargs -o docker stop"
Enter fullscreen mode Exit fullscreen mode

这些是我目前用来加速开发速度的别名。欢迎扩展它们,并通过 Twitter 与我分享。


本文最初发表于Blog.Kovah.de

文章来源:https://dev.to/kovah/useful-docker-shell-aliases-to-speed-up-develipment-3ck5
PREV
React 初学者项目构想
NEXT
厌倦了部署,我建立了自己的 Heroku