Docker撰写:扩展两种服务

时间:2018-04-25 16:31:09

标签: docker docker-compose dockerfile

我有以下 docker-compose

Collecting googleapis-common-protos (from gcloud==0.17.0->pyrebase)
  Using cached 


https://files.pythonhosted.org/packages/00/03/d25bed04ec8d930bcfa488ba81a2ecbf7eb36ae3ffd7e8f5be0d036a89c9/googleapis-common-protos-1.5.3.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/hugovillalobos/Documents/Code/FirebaseProject/FirebaseVenv/lib/python3.6/site-packages/setuptools/__init__.py", line 10, in <module>
    from setuptools.extern.six.moves import filter, filterfalse, map
  File "/Users/hugovillalobos/Documents/Code/FirebaseProject/FirebaseVenv/lib/python3.6/site-packages/setuptools/extern/__init__.py", line 1, in <module>
    from pkg_resources.extern import VendorImporter
  File "/Users/hugovillalobos/Documents/Code/FirebaseProject/FirebaseVenv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3017, in <module>
    @_call_aside
  File "/Users/hugovillalobos/Documents/Code/FirebaseProject/FirebaseVenv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3003, in _call_aside
    f(*args, **kwargs)
  File "/Users/hugovillalobos/Documents/Code/FirebaseProject/FirebaseVenv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3045, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/Users/hugovillalobos/Documents/Code/FirebaseProject/FirebaseVenv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2577, in activate
    declare_namespace(pkg)
  File "/Users/hugovillalobos/Documents/Code/FirebaseProject/FirebaseVenv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2151, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/Users/hugovillalobos/Documents/Code/FirebaseProject/FirebaseVenv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2091, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
  File "/Users/hugovillalobos/Documents/Code/FirebaseProject/FirebaseVenv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2120, in _rebuild_mod_path
    orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/ht/sqtnbdnx7r5562trfyn3827w0000gn/T/pip-install-ostv_w95/googleapis-common-protos/

至于 mysql.yml

version: '2'
services:
    cryptohds:
        image: cryptohds:cryptohds-2.0.0-SNAPSHOT
        environment:
            - APP_SLEEP=10 # gives time for the database to boot before the application
            - SPRING_DATASOURCE_DRIVER_CLASS_NAME=com.mysql.jdbc.Driver
            - SPRING_DATASOURCE_URL=jdbc:mysql://cryptohds-mysql:3306/cryptohds?useUnicode=true&characterEncoding=utf8&useSSL=false
            - SPRING_DATASOURCE_USERNAME=root
            - SPRING_DATASOURCE_PASSWORD=cryptohds
    cryptohds-mysql:
        extends:
            file: mysql.yml
            service: cryptohds-mysql

当缩放加密时,它们可以很好地扩展,但它们都使用相同的 cryptohds-mysql 。我想扩展加密,每个实例都有自己的 cryptohds-mysql

我怎样才能做到这一点?它们应该是两个在它们之间共享网络然后单独扩展它们的服务吗? 但在这种情况下,我如何使用SPRING_DATASOURCE_URL?

更新

我实际上已经构建了一个可以满足我需要的码头组合,但它并不是动态的。它专门创建了每个实例2个,我想要一个随机数。有没有其他方式动态这样做?或者只用脚本?

version: '2'
services:
    cryptohds-mysql:
        image: mysql:5.7.20
        environment:
            - MYSQL_USER=root
            - MYSQL_ROOT_PASSWORD=cryptohds
            - MYSQL_ALLOW_EMPTY_PASSWORD=yes
            - MYSQL_DATABASE=cryptohds
        ports:
            - 3306
        command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8 --explicit_defaults_for_timestamp

1 个答案:

答案 0 :(得分:1)

要将容器作为完全独立的组运行,我建议将它们定义为docker-compose中的单独“项目”。在群集模式中,等价物将部署单独的“堆栈”。项目名称默认为您当前的目录名称。您可以使用-p选项覆盖它,例如:

docker-compose -p cryptohds2 up