Docker-compose

 Docker-compose

 

 

docker-compose是容器编排工具,需要注意的是,docker-compose只是单机的容器编排工具

 

docker-compose 默认的配置文件为 : docker-compose.yaml

 

1 安装docker-compose

 

# 下载
?
docker文档 : `https://docs.docker.com/compose/install/`
    
1   sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    
2   sudo chmod +x /usr/local/bin/docker-compose
?
3   sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
?
4   docker-compose --version

 

 

2 docker-compose模板文件

 

version: "3.0"
services:
  django:
    image: django:v2
    ports:
    - "8080:8080"
    container_name: django
    networks:
      - django
    depends_on:
      - mysql
?
  mysql:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: admin123
      MYSQL_DATABASE: bbs09
    container_name: mysql
    volumes:
    - "/root/docker-compose/mysql/data:/var/lib/mysql"
    networks:
      - django
    depends_on:
      - redis
        
  redis:
    image: redis:latest
    container_name: redis
    networks:
      - django
networks:
  django:

 

 Docker-compose

 

 

3 docker-compose指令

 

# build
?
version: "3.0"
services:
  django:
    build:
      ./django
---
?
version: "3.0"
services:
  django:
    build:
      context: ./django
      dockerfile: Dockerfile
      args:
        NAME: python
        
# command    : 设置容器启动命令
?
# depends_on : 指定在某容器之后启动(依赖于某容器)
?
# env_file   : 指定环境变量文件

 

 

4 docker-compose参数

 

`启动`         : docker-compose up
?
`停止并删除`    : docker-compose down
?
`停止`         : docker-compose stop
?
`删除容器`      : docker-compose rm
?
`重启`         : docker-compose restart 容器名称
?
`进入容器`      : docker-compose exec 参数 service CMD
?
`容器列表`      : docker-compose ps
?
`查看容器进程`   : docker-compose top
?
`暂停运行`      : docker-compose pause
?
`恢复运行`      : docker-compose unpause

 

 

5 可视化工具

 

version: 3.0
services:
  portainer:
    image: portainer/portainer-ce
    ports:
    - "8001:8000"
    - "9001:9000"
    container_name: portainer
    networks:
      - "portainer"
    volumes:
    - "/var/run/docker.sock:/var/run/docker.sock"
    - "/root/docker-compose/portainer_data:/data"
    healthcheck:
      test: ["CMD", "ping", "-c1", "-t1", "portainer"]
      interval: 30s
      timeout: 10s
      retries: 3
?
networks:
  portainer:

 

 

Docker-compose

上一篇:PHP iconv 解决utf-8和gb2312编码转换问题


下一篇:斐波那契数列