mirror of
https://github.com/docker/compose.git
synced 2025-07-26 07:04:32 +02:00
Merge pull request #54 from orchardup/add-link-alias-without-project-name
Add link alias without project name
This commit is contained in:
commit
fae387168f
16
README.md
16
README.md
@ -75,8 +75,8 @@ from redis import Redis
|
|||||||
import os
|
import os
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
redis = Redis(
|
redis = Redis(
|
||||||
host=os.environ.get('FIGTEST_REDIS_1_PORT_6379_TCP_ADDR'),
|
host=os.environ.get('REDIS_1_PORT_6379_TCP_ADDR'),
|
||||||
port=int(os.environ.get('FIGTEST_REDIS_1_PORT_6379_TCP_PORT'))
|
port=int(os.environ.get('REDIS_1_PORT_6379_TCP_PORT'))
|
||||||
)
|
)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@ -274,22 +274,22 @@ If there are existing containers for a service, `fig up` will stop and recreate
|
|||||||
Fig uses [Docker links] to expose services' containers to one another. Each linked container injects a set of environment variables, each of which begins with the uppercase name of the container.
|
Fig uses [Docker links] to expose services' containers to one another. Each linked container injects a set of environment variables, each of which begins with the uppercase name of the container.
|
||||||
|
|
||||||
<b><i>name</i>\_PORT</b><br>
|
<b><i>name</i>\_PORT</b><br>
|
||||||
Full URL, e.g. `MYAPP_DB_1_PORT=tcp://172.17.0.5:5432`
|
Full URL, e.g. `DB_1_PORT=tcp://172.17.0.5:5432`
|
||||||
|
|
||||||
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i></b><br>
|
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i></b><br>
|
||||||
Full URL, e.g. `MYAPP_DB_1_PORT_5432_TCP=tcp://172.17.0.5:5432`
|
Full URL, e.g. `DB_1_PORT_5432_TCP=tcp://172.17.0.5:5432`
|
||||||
|
|
||||||
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i>\_ADDR</b><br>
|
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i>\_ADDR</b><br>
|
||||||
Container's IP address, e.g. `MYAPP_DB_1_PORT_5432_TCP_ADDR=172.17.0.5`
|
Container's IP address, e.g. `DB_1_PORT_5432_TCP_ADDR=172.17.0.5`
|
||||||
|
|
||||||
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i>\_PORT</b><br>
|
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i>\_PORT</b><br>
|
||||||
Exposed port number, e.g. `MYAPP_DB_1_PORT_5432_TCP_PORT=5432`
|
Exposed port number, e.g. `DB_1_PORT_5432_TCP_PORT=5432`
|
||||||
|
|
||||||
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i>\_PROTO</b><br>
|
<b><i>name</i>\_PORT\_<i>num</i>\_<i>protocol</i>\_PROTO</b><br>
|
||||||
Protocol (tcp or udp), e.g. `MYAPP_DB_1_PORT_5432_TCP_PROTO=tcp`
|
Protocol (tcp or udp), e.g. `DB_1_PORT_5432_TCP_PROTO=tcp`
|
||||||
|
|
||||||
<b><i>name</i>\_NAME</b><br>
|
<b><i>name</i>\_NAME</b><br>
|
||||||
Fully qualified container name, e.g. `MYAPP_DB_1_NAME=/myapp_web_1/myapp_db_1`
|
Fully qualified container name, e.g. `DB_1_NAME=/myapp_web_1/myapp_db_1`
|
||||||
|
|
||||||
|
|
||||||
[Docker links]: http://docs.docker.io/en/latest/use/port_redirection/#linking-a-container
|
[Docker links]: http://docs.docker.io/en/latest/use/port_redirection/#linking-a-container
|
||||||
|
@ -50,6 +50,10 @@ class Container(object):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return self.dictionary['Name'][1:]
|
return self.dictionary['Name'][1:]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name_without_project(self):
|
||||||
|
return '_'.join(self.dictionary['Name'].split('_')[1:])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def number(self):
|
def number(self):
|
||||||
try:
|
try:
|
||||||
|
@ -708,8 +708,11 @@ class Client(requests.Session):
|
|||||||
start_config['PublishAllPorts'] = publish_all_ports
|
start_config['PublishAllPorts'] = publish_all_ports
|
||||||
|
|
||||||
if links:
|
if links:
|
||||||
|
if isinstance(links, dict):
|
||||||
|
links = six.iteritems(links)
|
||||||
|
|
||||||
formatted_links = [
|
formatted_links = [
|
||||||
'{0}:{1}'.format(k, v) for k, v in sorted(six.iteritems(links))
|
'{0}:{1}'.format(k, v) for k, v in sorted(links)
|
||||||
]
|
]
|
||||||
|
|
||||||
start_config['Links'] = formatted_links
|
start_config['Links'] = formatted_links
|
||||||
|
@ -207,10 +207,11 @@ class Service(object):
|
|||||||
return max(numbers) + 1
|
return max(numbers) + 1
|
||||||
|
|
||||||
def _get_links(self):
|
def _get_links(self):
|
||||||
links = {}
|
links = []
|
||||||
for service in self.links:
|
for service in self.links:
|
||||||
for container in service.containers():
|
for container in service.containers():
|
||||||
links[container.name] = container.name
|
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):
|
||||||
|
@ -154,6 +154,7 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
db.start_container()
|
db.start_container()
|
||||||
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())
|
||||||
db.stop(timeout=1)
|
db.stop(timeout=1)
|
||||||
web.stop(timeout=1)
|
web.stop(timeout=1)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user