docker 光速入门-- 2. docker-compose & bash aliases

docker-compse

什么是docker-compose 它是由python 编写的, 前身是fig,通过yaml 配置文件管理多个docker 容器的命令行工具。当我们运行一个项目时,会有多个docker 容器互相配合完成的。比如 LNMP 环境,一般一个docker容器运行一个程序,(可以将docker 容器理解为单独的进程) ,这时候如果用docker 命令一个一个去管理会显得非常麻烦,这时候就体现出docker-compse的好处了

安装

我的环境是 VMware + centos7 , docker-compose 是python写得,是通过pip安装的, centos 7 默认不带pip,首先我们安装pip

安装pip

1. 添加epel 源

$ sudo yum install python-pip

 

2. 安装pip

$ sudo yum install python-pip
$ docker-compose  --version
docker-compose version 1.23.2, build 1110ad0

至此docker-compose 安装好了。其他方法参考 install docker-compose

docker-compose bash alias

当我们在使用docker-compose 时 每次都要敲那么长的命令,很烦。至此小弟在github 上找了段jio本,可能需要梯子@jodumontjodumont/bash_aliases-docker-compose

  1. curl -ko $HOME/.bash_aliases-docker-compose https://gist.githubusercontent.com/jodumont/d8ade3ab173700e3369f04fbe0334fde/raw/ced78642a5682e7ec6ee7fc89367b929ef35f366/bash_aliases-docker-compose
  2. echo -e "\nif [ -f ~/.bash_aliases-docker-compose ]; then \n. ~/.bash_aliases-docker-compose\nfi" >> $HOME/.bashrc
  3. . $HOME/.bashrc

词汇表

  • dcu == Docker-Compose Up
  • dcl == Docker-Compose Logs
  • dcs == Docker-Compose Stop
  • dcsr == Docker-Compose Stop & Remove
  • dcsr == Docker-Compose Stop, Remove & Up

也可以将此段代码复制到 .bash_aliases-docker-compose

docker-compose aliases
## How to install/use it
### 1. $ curl -ko $HOME/.bash_aliases-docker-compose https://gist.githubusercontent.com/jodumont/[...]/bash_aliases-docker-compose
### 2. $ echo -e "\nif [ -f ~/.bash_aliases-docker-compose ]; then \n. ~/.bash_aliases-docker-compose\nfi" >> $HOME/.bashrc
### 3. $ . $HOME/.bashrc

## dcu == Docker-Compose Up
alias dcu="docker-compose up -d --remove-orphans"

## dcl == Docker-Compose Logs
alias dcl="docker-compose logs"

## dcs == Docker-Compose Stop
### Else like : dcs discovery # which is the name of a container inside this composition
function dcs {
  if [ -z "$1" ]; then
    docker-compose stop
  else
    for n in $@
      do
        docker-compose stop "$n"
      done
  fi
}

## dcsr == Docker-Compose Stop & Remove
alias dcsr="docker-compose stop && yes|docker-compose rm"

## dcsr == Docker-Compose Stop, Remove & Up
alias dcsru="docker-compose stop && yes|docker-compose rm && docker-compose up -d --remove-orphans"

有兴趣的自己研究吧

你可能感兴趣的:(docker,docker-compose)