码迷,mamicode.com
首页 > 其他好文 > 详细

Docker-compose

时间:2021-06-28 17:54:10      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:docker   pytho   django   重启   air   admin   use   sudo   down   

 技术图片

 

 

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:

 

 技术图片

 

 

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

标签:docker   pytho   django   重启   air   admin   use   sudo   down   

原文地址:https://www.cnblogs.com/chijintao/p/14932458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!