docker-compose 管理多个docker容器实例

Compose 安装

运行此命令下载最新版本的Docker Compose

$ curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

对二进制文件应用可执行权限

$ chmod +x /usr/local/bin/docker-compose

验证

$ docker-compose --version
docker-compose version 1.16.1, build 6d1ac21



用镜像 pre-official-ui 启动多个容器实例

root@weifeng02 ~]# docker images
REPOSITORY                                                                TAG                 IMAGE ID            CREATED             SIZE
<none>                                                                    <none>              b0bd7b10a79d        4 weeks ago         276 MB
pre-official-ui                                                           latest              0069c632f5de        5 weeks ago         276 MB


[root@weifeng02 ~]# cat docker-compose.yml 
nginx02:
   image: pre-official-ui
   ports:
      - 80


启动命令  

[root@weifeng02 ~]# docker-compose up -d   --scale nginx02=5
Starting root_nginx02_1 ... done
Starting root_nginx02_2 ... done
Starting root_nginx02_3 ... done
Starting root_nginx02_4 ... done
Starting root_nginx02_5 ... done


显示已经启动的容器实例 
[root@weifeng02 ~]# docker-compose ps
     Name        Command   State               Ports             
-----------------------------------------------------------------
root_nginx02_1   nginx     Up      443/tcp, 0.0.0.0:32796->80/tcp
root_nginx02_2   nginx     Up      443/tcp, 0.0.0.0:32797->80/tcp
root_nginx02_3   nginx     Up      443/tcp, 0.0.0.0:32798->80/tcp
root_nginx02_4   nginx     Up      443/tcp, 0.0.0.0:32795->80/tcp
root_nginx02_5   nginx     Up      443/tcp, 0.0.0.0:32794->80/tcp


关闭启动的容器实例
[root@weifeng02 ~]# docker-compose stop nginx02
Stopping root_nginx02_1 ... done
Stopping root_nginx02_3 ... done
Stopping root_nginx02_5 ... done
Stopping root_nginx02_4 ... done
Stopping root_nginx02_2 ... done

开启多个容器实例

[root@weifeng02 ~]# docker-compose start nginx02
Starting nginx02 ... done
[root@weifeng02 ~]# 
[root@weifeng02 ~]# docker-compose ps
     Name        Command   State               Ports             
-----------------------------------------------------------------
root_nginx02_1   nginx     Up      443/tcp, 0.0.0.0:32799->80/tcp
root_nginx02_2   nginx     Up      443/tcp, 0.0.0.0:32803->80/tcp
root_nginx02_3   nginx     Up      443/tcp, 0.0.0.0:32800->80/tcp
root_nginx02_4   nginx     Up      443/tcp, 0.0.0.0:32802->80/tcp
root_nginx02_5   nginx     Up      443/tcp, 0.0.0.0:32801->80/tcp

  



猜你喜欢

转载自www.cnblogs.com/weifeng1463/p/10402686.html
今日推荐