Docker-compose: deploying service in multiple hosts

前端 未结 4 2131
耶瑟儿~
耶瑟儿~ 2020-12-23 14:02

I have a docker-compose file that deploys 8 different docker services in the same host. Is it possible to deploy it in different hosts?, I would like to deploy some service

4条回答
  •  不知归路
    2020-12-23 14:38

    With docker swarm mode, you can deploy a version 3 compose yml file using:

    docker stack deploy -c docker-compose.yml $your_stack_name
    

    The v3 syntax removes a few features that do not apply to swarm mode, like links and dependencies. You should also note that volumes are stored local to a node by default. Otherwise the v3 syntax is very similar to the v2 syntax you may already be using. See ether following for more details:

    https://docs.docker.com/compose/compose-file/

    https://docs.docker.com/engine/swarm/


    [ Original answer before v3 of the docker-compose.yml ]

    For a single docker-compose.yml to deploy to multiple hosts, you need to use the standalone swarm (not the newer swarm mode, yet, this is rapidly changing). Spin up a swarm manager that has each host defined as members of its swarm, and then you can use constraints inside your docker-compose.yml to define which services run on which hosts.

    You can also split up your docker-compose.yml into several files, one for each host, and then run multiple docker-compose up commands, with a different DOCKER_HOST value defined for each.

    In both cases, you'll need to configure your docker installs to listen on the network, which should be done by configuring TLS on those sockets. This documentation describes what you need to do for that.

提交回复
热议问题