美文网首页
Docker compose

Docker compose

作者: Plenari | 来源:发表于2019-10-07 15:25 被阅读0次

我之前总是写很长的命令去启动一个容器,然后进去再执行一些命令。然后在执行下一个容器。现在我想我应该接触compose,有结构的组织一下这些启动方法了。

1. dockerfile

FROM images:flag
ENV PYTHON 1
ADD ./code
ADD requ.txt
WORKDIR /code
RUN pip install -r requ.txt
CMD python app.py

将以上命令改成compose> docker-compose.yml:

version: '3'
services:
     redis:
        images: redis
        restart:alwarys
    web:
        build: .
        command : python app.py
        volumes: 
            - .:/code
        ports:
         - "8000":"8000"
        depends_on:
                - redis
        environment:
        - versin: 1.2
        - pass: 123456

        workdir_dir: /app


启动关闭

docker-compose up --compose-file docker-compose.yml
docker-compose up
docker-compose down
docker-compose scale web=3 db=2将启动3个容器运行web服务,2个容器运行db服务。

其他命令

docker-compose up -d 在后台运行服务容器。

docker network-mode
docker networks

参考

6.一个例子

version: "3"
services:
  db:
    image: mysql:5.6  
    environment:
      - MYSQL_HOST=localhost
      - MYSQL_DATABASE=opsmanage
      - MYSQL_USER="数据库用户名"
      - MYSQL_PASSWORD="数据库用户密码"
      - MYSQL_ROOT_PASSWORD="数据库root密码"
    volumes:
      - /data/apps/mysql:/var/lib/mysql  
    restart: always  
    networks:
      - default
  redis:
     container_name: redis
     image: redis:3.2.8
     command: redis-server 
     ports:
       - "6379:6379"
     volumes:
       - /data/apps/redis:/data/redis
     networks:
       - default  
  rabbitmq:
     container_name: rabbitmq
     image: rabbitmq:management
     ports:
       - "5672:5672"
       - "15672:15672"
     networks:
       - default  

  ops_web:
     image: opsmanage-base:latest
     container_name: ops_web
     environment:
       MYSQL_DATABASE: opsmanage
       MYSQL_USER: "数据库用户名"
       MYSQL_PASSWORD: "数据库用户密码"
     ports:
       - "8000:8000" #vim /mnt/OpsManage/OpsManage/settings.py文件里面的DEBUG设置为DEBUG = False 
     volumes:
       - /mnt/OpsManage:/data/apps/opsmanage
       - /mnt/OpsManage/upload:/data/apps/opsmanage/upload
       - /mnt/OpsManage/logs:/data/apps/opsmanage/logs
     command: bash /data/apps/opsmanage/docker/start.sh  
     links:
       - db
       - redis
       - rabbitmq
     depends_on:
       - db
       - redis
       - rabbitmq
     restart: always
     networks:
       - default  

networks:
  default:

相关文章

网友评论

      本文标题:Docker compose

      本文链接:https://www.haomeiwen.com/subject/bddmpctx.html