Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Containers can't communicate with each other #2716

Closed
steve-taylor opened this issue Mar 17, 2019 · 6 comments
Closed

Containers can't communicate with each other #2716

steve-taylor opened this issue Mar 17, 2019 · 6 comments

Comments

@steve-taylor
Copy link

RancherOS Version: 1.5.1

Where are you running RancherOS? DigitalOcean

My cloud config specifies two containers. One is based on Node.js and the other is Redis. They should be able to communicate with each other using their container names, but webapp cannot connect to redis using redis as the host name.

#cloud-config

rancher:
  registry_auths:
    "registry.gitlab.com":
      auth: REDACTED
  services:
    webapp:
      image: registry.gitlab.com/REDACTED/webapp/webapp:latest
      restart: always
      ports:
      - "80:3000"
      links:
      - "redis:redis"
    redis:
      image: redis:5.0.3-alpine
      container_name: redis
      ports:
      - "6379:6379"

From docker logs redis:

Error: Redis connection to redis:6379 failed - getaddrinfo ENOTFOUND redis redis:6379
@steve-taylor
Copy link
Author

I tried making it more explicit, but it still doesn't work.

#cloud-config

rancher:
  registry_auths:
    "registry.gitlab.com":
      auth: REDACTED
  services:
    webapp:
      image: registry.gitlab.com/REDACTED/webapp/webapp:latest
      restart: always
      ports:
      - "80:3000"
      networks:
      - foobar
    redis:
      image: redis:5.0.3-alpine
      container_name: redis
      ports:
      - "6379:6379"
      networks:
      - foobar
  networks:
    ssltimer:
      driver: bridge
      name: foobar

Also, it seems that networks are completely ignored.

$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
258d3ac6c703        bridge              bridge              local
86b246106e49        host                host                local
ca31c796b4ca        none                null                local

@steve-taylor
Copy link
Author

It must be an issue with the default Docker engine (18.x.x).

This fixed the config (the one with links, not networks, which I haven't tried with this fix):

  docker:
    engine: docker-17.12.1-ce

I wonder if Rancher OS has some Docker 18 compatibility issues that need to be addressed. It doesn't seem right that, by default, containers cannot communicate with each other by their name. For that reason, although I have a workaround, I'm not going to close this issue.

@Jason-ZW
Copy link

@steve-taylor Seems cannot reproduce your issue.

[root@rancheros conf]# docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:20:43 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:28:38 2018
  OS/Arch:          linux/amd64
  Experimental:     false
[root@rancheros conf]# ros c export
hostname: rancheros
rancher:
  environment:
    EXTRA_CMDLINE: /init
  network:
    interfaces:
      eth0:
        dhcp: true
      eth1:
        dhcp: true
      lo:
        address: 127.0.0.1/8
  services:
    test1:
      image: nginx
    test2:
      depends_on:
      - test1
      image: nginx
      links:
      - test1
[root@rancheros conf]# docker exec -it test2 bash
root@7317f2a63c88:/# curl test1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

@steve-taylor
Copy link
Author

@Jason-ZW thanks for your detailed example. It looks like additional configuration is required when using Docker engine 18 vs 17. I’m not sure if this is called out anywhere. The documentation is quite thin. I’ll give this a try and see if it works in my case.

@steve-taylor
Copy link
Author

  network:
    interfaces:
      eth0:
        dhcp: true
      eth1:
        dhcp: true
      lo:
        address: 127.0.0.1/8

This seems to have broken the network. I'm getting network unreachable.

@chosten
Copy link

chosten commented Feb 23, 2020

I had the same issue.
The containers started to communicate again after creating a new bridge network and connecting all the containers to it.

@rancher rancher locked and limited conversation to collaborators Mar 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants