运行多个Docker将文件组合在一起

multidocker的Python项目详细描述


多码头

将多个撰写文件作为一个运行。

为什么?什么时候?怎样?什么?

我使用一个反向代理容器使几个容器可以通过https访问。 因此,容器需要在同一个合成文件中。 过了一段时间,文件开始失控,所以我编写了这个工具,使其更易于管理。

设置

0个。要求

  • docker
  • docker-compose
  • python 3.6+

一。安装MultiDocker

$ pip3 install multidocker

2.设置目录

您需要以下设置:

$ tree
multidocker/
├── some_app/
│   └── docker-compose.yml
└── other_app/
    └── docker-compose.yml

示例

$ tree
multidocker/
├── nextcloud/
│   └── docker-compose.yml
└── proxy/
    ├── docker-compose.yml
    ├── htpasswd
    ├── nginx-extra-options.conf
    └── vhost.d/

nextcloud/docker-compose.yml

---
version: '3.6'

# these two containers share the nextcloud
# network over which they will communicate
services:
  nextcloud:
    restart: unless-stopped
    image: nextcloud
    environment:
      VIRTUAL_HOST: "my_hostname.example.com"
      VIRTUAL_PORT: 80
      LETSENCRYPT_HOST: "my_hostname.example.com"
    volumes:
      - nextcloud_data:/var/www/html:rw
    # this adds the 'multidocker' network that allows
    # communication between compose files
    external: true
    networks:
      - nextcloud
    depends_on:
      - nextcloud_db

  nextcloud_db:
    restart: unless-stopped
    image: postgres:10.4
    environment:
      POSTGRES_PASSWORD: "secret"
      POSTGRES_USER: "nextcloud"
    volumes:
      - nextcloud_db:/var/lib/postgresql/data:rw
    networks:
      - nextcloud
...

proxy/docker-compose.yml

---
version: '3.6'
services:

  nginx:
    image: jwilder/nginx-proxy:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - nginx_conf:/etc/nginx/conf.d:rw
      - ./nginx-extra-options.conf:/etc/nginx/conf.d/extra.conf:ro
      - ./htpasswd:/etc/nginx/htpasswd_default:ro
      - ./vhost.d:/etc/nginx/vhost.d:ro
      - nginx_html:/usr/share/nginx/html:ro
      - nginx_dhparam:/etc/nginx/dhparam:rw
      - certificates:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    # this adds the 'multidocker' network that allows
    # communication between compose files
    external: true
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"


  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    volumes:
      - nginx_conf:/etc/nginx/conf.d:rw
      - nginx_vhost:/etc/nginx/vhost.d:rw
      - nginx_html:/usr/share/nginx/html:rw
      - certificates:/etc/nginx/certs:rw
      - /var/run/docker.sock:/var/run/docker.sock:ro
    depends_on:
      - nginx
...

(其他文件在那里演示)

用法

您可以使用所有的docker-compose命令:ps、up、down、logs等。

一次性使用

$ multidocker up -d
Creating network "multidocker_nextcloud_nextcloud" with the default driver
Creating network "multidocker_multidocker" with the default driver
Creating volume "multidocker_nextcloud_nextcloud_data" with default driver
Creating volume "multidocker_nextcloud_nextcloud_db" with default driver
Creating volume "multidocker_proxy_certificates" with default driver
Creating volume "multidocker_proxy_nginx_conf" with default driver
Creating volume "multidocker_proxy_nginx_dhparam" with default driver
Creating volume "multidocker_proxy_nginx_html" with default driver
Creating nextcloud_nextcloud_db ... done
Creating proxy_nginx            ... done
Creating nextcloud_nextcloud    ... done

交互模式

我还添加了一个交互模式。您可以在不带任何参数的情况下运行multidocker来启动它:

$ multidocker
Interactive Mode

You can run docker subcommands here, like so:
        ------------------------------------------
        | multidocker> ps                        ||     Name        Command  State   Ports || ---------------------------------------|| container_name  /init    Up            || multidocker>                           |
        ------------------------------------------

Commands:
  build              Build or rebuild services
  bundle             Generate a Docker bundle from the Compose file
  config             Validate and view the Compose file
  create             Create services
  down               Stop and remove containers, networks, images, and volumes
  events             Receive real time events from containers
  exec               Execute a command in a running container
  help               Get help on a command
  images             List images
  kill               Kill containers
  logs               View output from containers
  pause              Pause services
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pull service images
  push               Push service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  top                Display the running processes
  unpause            Unpause services
  up                 Create and start containers
  version            Show the Docker-Compose version information

Multidocker Commands:
  cat                Output combined compose file to disk
  help               Show this help text
  reload             Reload the compose files from disk
  write              Write the combined compsose file to disk
  quit, exit         Exit interactive mode (ctrl+d also works)

您可以在这个提示下运行所有docker compose命令。它省去了在每个命令前键入multidocker的麻烦。 它还节省了时间,因为它将组合的合成文件保存在内存中。如果更改了一个撰写文件,则应运行reload命令。

改进:

  • []文件更改时自动重新加载
  • []在交互模式下使用readline
  • []交互式模式下的外壳式历史记录
  • []升级到python 3.7以使用改进的subprocess.run
  • []检查示例是否实际有效

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在Java中为上传的文件设计强制的文件夹结构   java我如何在下面的代码中解决这个>错误HTTP Status 404   java如何在方面字段Lucene上添加分页   java My 安卓应用程序在尝试10次后崩溃   java“找不到Spring NamespaceHandler”错误   连接到Dynamodb时发生java AWS lambda错误   过程的价值。JAVA中的exitValue()   eclipse vscode java正在尝试设置项目   JavaEclipse不再自动在javadocs中添加标签   java找不到LoggerFactory类   在Java中实现延迟   设置onClickListener时的java NullPointerException   用jsoup解析HTML:Android和Java的区别