No internet connection
  1. Home
  2. Ideas

Using static IP addresses?

By Dashamir Hoxha @dashohoxha
    2021-03-26 09:46:34.086Z

    Using static IP addresses for the containers seems suspicious and unnecessary:
    https://github.com/debiki/talkyard-prod-one/blob/master/docker-compose.yml#L19

    I don't see why you can't use service names or aliases:
    https://docs.docker.com/compose/compose-file/compose-file-v3/#aliases

    But again I may be wrong, since I don't know all the details.

    Solved in post #4, click to view
    • 3 replies
    1. There's an explanation about the IP addresses in the .env file:
      https://github.com/debiki/talkyard-prod-one/blob/895b7aa6e2deee5dac0e9551d278a4d6195136de/.env#L28

      Talkyard did use hostnames / aliases previously, but then Docker, after the restart of one container, sometimes gave it a new IP address, causing problems when the other containers, or [OS or Talkyard web / app server components] in those other containers, didn't notice that the IP address had changed.

      (For example, if I remember correctly, requests from the Web container to the App container, could fail, for no obvious reason, after the App container had gotten restarted. Didn't happen often, but sometimes.)

      The IP addresses are private, in an internal Docker network, not accessible from outside.

      1. Dashamir Hoxha @dashohoxha
          2021-03-29 16:18:51.096Z

          (For example, if I remember correctly, requests from the Web container to the App container, could fail, for no obvious reason, after the App container had gotten restarted. Didn't happen often, but sometimes.)

          I think that from the web container you can refer to the app container using the hostname app, for example like this: http://app:9000, instead of using an IP. I don't see why this should fail, unless Docker has some bugs and doesn't work as expected.

          Anyway, you know it better than me.

          1. Yes, that's how it's done :- )   in server-locations.conf for Nginx: (as of April 2021)

            proxy_pass http://app:9000/;
            

            The thing is, app:s IP address will be the same, always. Otherwise, not often but sometimes (at least in the past), if app got stopped / removed, and restarted, it could get a new IP address, but Nginx continued trying to access the old IP address (until the Web container got restarted, it too, and Nginx inside picked up the new IP).

            Reply1 LikeSolution