Last active
January 4, 2016 02:19
-
-
Save garthk/8553920 to your computer and use it in GitHub Desktop.
Do docker's environment variables for container linking make as much sense as we'd like?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# show VICTIM_A_PORT_80_TCP_PORT=80 because repetition | |
docker build -t=polite-listener . | |
docker run -d -p 80 -name fake80a polite-listener | |
docker run -d -p 80 -name fake80b polite-listener | |
docker run -rm -i -link fake80a:VICTIM_A -link fake80b:VICTIM_B stackbrew/ubuntu env | |
docker stop fake80a fake80b | |
docker rm fake80a fake80b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# show VICTIM_PORT=tcp://172.17.0.35:8000 because clobbered | |
docker build -t=polite-listener . | |
docker run -d -p 8000 -p 8001 -name victim multi-listen 8000 8001 | |
docker run -rm -i -link victim:VICTIM stackbrew/ubuntu env | |
docker stop victim | |
docker rm victim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Politely listens on the nominated TCP ports. | |
FROM stackbrew/ubuntu | |
ADD multi-listen /usr/local/bin/multi-listen | |
RUN chmod a+x /usr/local/bin/multi-listen | |
ENTRYPOINT ["/usr/local/bin/multi-listen"] | |
CMD ["80"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Politely listens to ports. | |
# Unlike 'nc', supports >1 port and will obey 'docker stop'. | |
PIDS= | |
for PORT in $*; do | |
nc -l $PORT & PIDS=$| $PIDS | |
done | |
trap 'kill 0' SIGINT SIGTERM EXIT | |
wait $PIDS |
Updated to show ${ALIAS}_PORT
clobbering when linking to a victim with multiple ports. That makes the variable unsafe: you could test with ${ALIAS}_PORT
, be happy, and then get broken later when they expose another port.
Michael Crosby confirms that the port you see in your container isn't guaranteed to match the port the original container exposed. It is now, because source code, but they might change that in the future.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From a debate about the environment variables for container linking involving @SvenDowideit, @cmelbye, and @tianon:
Under docker 0.7.6, the variables become:
The extra
80_
element in all but the top-level environment variable (linkname_PORT
) is redundant, as it has no information to expose.