Container networking
TLDR;
Opctl attaches all containers to a virtual overlay network and bridges it to the opctl host.
Adding a name attribute to container(s) makes it resolvable from other containers and the host by that name.
If multiple containers have the same name the ips of all containers will be resolved as is standard for DNS A records.
Example
-
Run this op:
name: containerNetworking
run:
parallel:
- container:
image: { ref: nginx }
# some syntactically valid hostname
name: nginx.demo.wow
- container:
image: { ref: alpine }
cmd:
- sh
- -ce
- |
# wait up
sleep 1; until ping -c1 nginx.demo.wow >/dev/null 2>&1; do :; done
# ping forever
ping nginx.demo.wow -
Observe the second container succeeds in
ping
ing thenginx.demo.wow
container. -
On the opctl host, open a terminal and
ping nginx.demo.wow
; observe successful pings to thenginx.demo.wow
container. -
On the opctl host, open a browser and visit
http://nginx.demo.wow
; observe the nginx default webpage is returned.