Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

couldn't access traefik gateway or svc behind it #1

Open
RichardLee0211 opened this issue May 12, 2022 · 2 comments
Open

couldn't access traefik gateway or svc behind it #1

RichardLee0211 opened this issue May 12, 2022 · 2 comments

Comments

@RichardLee0211
Copy link

First, great talk, Meysam. Highlight of the conference.
New to Docker Compose, Followed alone, but not really understand network_mode: "host" option in traefic gateway.

from: https://docs.docker.com/compose/compose-file/#network_mode
gives the container raw access to host’s network interface
not sure what it means

and my setup failed to curl svc.dockercon2022.com and localhost:8080
feel like I missed some point

here's the situation:

vislab@vislab-MS-7845 [10:34:45 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/individual-services/traefik] [master]
-> % tail -n 3 /etc/hosts                                                                                                                                                                                                                                                                
# for dockercon2022 test
127.0.0.1    svc.dockercon2022.com
127.0.0.1    svc-crud.dockercon2022.com

vislab@vislab-MS-7845 [10:40:56 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/individual-services/traefik] [master]
-> % docker-compose version 
Docker Compose version v2.5.0

vislab@vislab-MS-7845 [10:41:31 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/individual-services/traefik] [master]
-> % docker-compose up -d 
[+] Running 1/1
 ⠿ Container traefik-gateway-1  Started                                                                                                0.2s

vislab@vislab-MS-7845 [10:41:37 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/individual-services/traefik] [master]
-> % curl localhost:8080
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Connection refused

vislab@vislab-MS-7845 [10:42:38 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/individual-services/traefik] [master]
-> % docker-compose ls 
NAME                STATUS              CONFIG FILES
traefik             running(1)          /home/vislab/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/individual-services/traefik/docker-compose.yml

or use entire-platform

vislab@vislab-MS-7845 [10:45:29 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform] [master]
-> % docker-compose up -d 
[+] Running 13/13
 ⠿ Network dockercon2022_redis             Created                                                                                                                                                                                                                                   0.0s
 ⠿ Network dockercon2022_svc1              Created                                                                                                                                                                                                                                   0.0s
 ⠿ Network dockercon2022_svc2              Created                                                                                                                                                                                                                                   0.0s
 ⠿ Network dockercon2022_svc3              Created                                                                                                                                                                                                                                   0.0s
 ⠿ Network dockercon2022_postgres          Created                                                                                                                                                                                                                                   0.0s
 ⠿ Container dockercon2022-svc2-copy-1     Started                                                                                                                                                                                                                                   1.6s
 ⠿ Container dockercon2022-gateway-1       Started                                                                                                                                                                                                                                   0.5s
 ⠿ Container dockercon2022-svc2-1          Started                                                                                                                                                                                                                                   1.5s
 ⠿ Container dockercon2022-redis-1         Started                                                                                                                                                                                                                                   1.3s
 ⠿ Container dockercon2022-postgres-1      Started                                                                                                                                                                                                                                   1.0s
 ⠿ Container dockercon2022-svc1-1          Started                                                                                                                                                                                                                                   1.2s
 ⠿ Container dockercon2022-svc3-migrate-1  Started                                                                                                                                                                                                                                   1.6s
 ⠿ Container dockercon2022-svc3-1          Started                                                                                                                                                                                                                                   2.0s

vislab@vislab-MS-7845 [10:45:45 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform] [master]
-> % docker-compose ls 
NAME                STATUS              CONFIG FILES
dockercon2022       running(7)          /home/vislab/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform/compose-traefik.yml,/home/vislab/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform/compose-svc1.yml,/home/vislab/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform/compose-svc2.yml,/home/vislab/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform/compose-svc2-copy.yml,/home/vislab/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform/compose-svc3.yml,/home/vislab/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform/compose-postgres.yml,/home/vislab/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform/compose-redis.yml

vislab@vislab-MS-7845 [10:45:50 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform] [master]
-> % curl http://svc.dockercon2022.com/v1/
curl: (7) Failed to connect to svc.dockercon2022.com port 80 after 0 ms: Connection refused

vislab@vislab-MS-7845 [10:47:03 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform] [master]
-> % nslookup svc.dockercon2022.com 
Server:         127.0.0.53
Address:        127.0.0.53#53

Name:   svc.dockercon2022.com
Address: 127.0.0.1

vislab@vislab-MS-7845 [10:47:36 PM] [~/Downloads/20220510_DockerConf/testDir/test002/dockercon2022-talk/entire-platform] [master]
-> % curl localhost:8080
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Connection refused

@meysam81
Copy link
Owner

Thanks, @RichardLee0211 for bringing this up and for the kind words. I have faced some issues with the macOS earlier, could you specify why OS you're using?

Also, to answer your question,network_mode: host is just as if you run the application in your host machine without any container because the application inside the container would attach to the network of your local machine; therefore naming "host". This means that if the application is opening ANY port, that port will be exposed on your local machine.

For example, if I run nginx with the network_mode: host mode, it would simply be as if I run the Nginx binary inside my machine, listening on port 80 and giving access to anyone inside my network to see the index page of the Nginx.

I hope this clears things up for you.

@RichardLee0211
Copy link
Author

weird, It's ubuntu 22.04

-> % uname -a
Linux vislab-MS-7845 5.15.0-27-generic #28-Ubuntu SMP Thu Apr 14 04:55:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants