Skip to content

Instantly share code, notes, and snippets.

@bobvanderlinden
Last active October 13, 2021 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobvanderlinden/6ad58a31be0ab9f1572d23a8ccb66300 to your computer and use it in GitHub Desktop.
Save bobvanderlinden/6ad58a31be0ab9f1572d23a8ccb66300 to your computer and use it in GitHub Desktop.
docker-compose host access test

Run run.sh. Expected output:

test-a_1  | ok host
test-b_1  | ok host.docker.internal:host-gateway
test-c_1  | ok host.docker.internal
version: "3.7"
services:
listen:
build: .
ports:
- "8888:8888"
command: bash -c "nc -vkl 8888"
init: true
test-a:
build: .
extra_hosts:
- host:host-gateway
environment:
- ADDRESS=host
test-b:
build: .
extra_hosts:
- host.docker.internal:host-gateway
environment:
- ADDRESS=host.docker.internal
test-c:
build: .
environment:
- ADDRESS=host.docker.internal
test-d:
build: .
environment:
- ADDRESS=listen
FROM ubuntu
RUN apt-get update
RUN apt-get -y install netcat
CMD nc -zv -w 1 $ADDRESS 8888
docker-compose up -d listen; docker-compose up test-{a,b,c}; docker-compose down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment