mirror of
https://github.com/docker/compose.git
synced 2025-07-24 06:04:57 +02:00
Merge pull request #67 from orchardup/link-services-to-themselves
Link services to themselves
This commit is contained in:
commit
62607f4f04
@ -47,6 +47,12 @@ For example:
|
|||||||
|
|
||||||
Note that this will not start any services that the command's service links to. So if, for example, your one-off command talks to your database, you will need to run `fig up -d db` first.
|
Note that this will not start any services that the command's service links to. So if, for example, your one-off command talks to your database, you will need to run `fig up -d db` first.
|
||||||
|
|
||||||
|
One-off commands are started in new containers with the same config as a normal container for that service, so volumes, links, etc will all be created as expected. The only thing different to a normal container is the command will be overridden with the one specified and no ports will be created in case they collide.
|
||||||
|
|
||||||
|
Links are also created between one-off commands and the other containers for that service so you can do stuff like this:
|
||||||
|
|
||||||
|
$ fig run db /bin/sh -c "psql -h \$DB_1_PORT_5432_TCP_ADDR -U docker"
|
||||||
|
|
||||||
## scale
|
## scale
|
||||||
|
|
||||||
Set number of containers to run for a service.
|
Set number of containers to run for a service.
|
||||||
|
@ -212,6 +212,9 @@ class Service(object):
|
|||||||
for container in service.containers():
|
for container in service.containers():
|
||||||
links.append((container.name, container.name))
|
links.append((container.name, container.name))
|
||||||
links.append((container.name, container.name_without_project))
|
links.append((container.name, container.name_without_project))
|
||||||
|
for container in self.containers():
|
||||||
|
links.append((container.name, container.name))
|
||||||
|
links.append((container.name, container.name_without_project))
|
||||||
return links
|
return links
|
||||||
|
|
||||||
def _get_container_options(self, override_options, one_off=False):
|
def _get_container_options(self, override_options, one_off=False):
|
||||||
|
@ -155,8 +155,13 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
web.start_container()
|
web.start_container()
|
||||||
self.assertIn('figtest_db_1', web.containers()[0].links())
|
self.assertIn('figtest_db_1', web.containers()[0].links())
|
||||||
self.assertIn('db_1', web.containers()[0].links())
|
self.assertIn('db_1', web.containers()[0].links())
|
||||||
db.stop(timeout=1)
|
|
||||||
web.stop(timeout=1)
|
def test_start_container_creates_links_to_its_own_service(self):
|
||||||
|
db1 = self.create_service('db')
|
||||||
|
db2 = self.create_service('db')
|
||||||
|
db1.start_container()
|
||||||
|
db2.start_container()
|
||||||
|
self.assertIn('db_1', db2.containers()[0].links())
|
||||||
|
|
||||||
def test_start_container_builds_images(self):
|
def test_start_container_builds_images(self):
|
||||||
service = Service(
|
service = Service(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user