Internet does not work in docker

There is no internet in containers. Also, apparently, nginx has some problems with fpm, if you look at the logs, you can see the following error:

2020/03/30 15:55:21 [error] 6#6: *4 connect() failed (113: No route to host) while connecting to upstream, client: 10.0.2.2, server: , request: "GET /wpad.dat HTTP/1.1", upstream: "fastcgi://172.18.0.2:9000", host: "wpad.beeline"

All this works on VirtualBox on CentOS 8, network settings: https://i.imgur.com/apXpS4b.png

nginx/default:

server {
     listen 80;
     index index.php index.html;
     root /app/public;

     location / {
         try_files $uri /index.php?$args;
     }

     location ~ \.php$ {
         try_files $uri =404;
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass manager-php-fpm:9000;
         fastcgi_index index.php;
         include fastcgi_params;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         fastcgi_param PATH_INFO $fastcgi_path_info;
     }
 }

nginx.docker:

FROM nginx:1.17.9-perl

COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf

WORKDIR /app

php-cli.docker:

FROM php:7.4-cli

RUN apt-get update && apt-get install -y unzip

WORKDIR /app

COPY ./ ./

php-fpm.docker

FROM php:7.4-fpm

WORKDIR /app

docker-compose.yml:

version: '3'
services:
  manager-nginx:
    build:
      context: ./manager/docker/development
      dockerfile: nginx.docker
    volumes:
      - ./manager:/app
    depends_on:
      - manager-php-fpm
    ports:
      - "80:80"
  manager-php-fpm:
    build:
      context: ./manager/docker/development
      dockerfile: php-fpm.docker
    volumes:
      - ./manager:/app
  manager-php-cli:
    build:
      context: ./manager/docker/development
      dockerfile: php-cli.docker
    volumes:
      - ./manager:/app

If in php-cli.docker add

RUN apt-get update && apt-get install -y unzip

there will be an error with the package manager

Reading package lists...
W: Failed to fetch http://deb.debian.org/debian/dists/buster/InRelease  Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/buster/updates/InRelease  Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/buster-updates/InRelease  Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.

The virtual machine resolve DNS names https://i.imgur.com/OiyHpO9.png

For some reason there are no containers

[iam@localhost ~]$ docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "bf73901df41df980c3619a2eb9281039edd09dab4768468fa08487e3f4d248b2",
        "Created": "2020-03-30T17:47:12.591249611-04:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

Docker compose creates a user-defined bridge network per project and connects all the services to it. Find your networks with docker network ls.

You need to make sure your local network configuration doesn’t block this network to access the internet somehow. If you know the default network bridge has access to the internet, you can tell Docker Compose to connect your containers to that one by adding the following to each service:

services:
  manager-nginx:
    # ...
    network_mode: bridge
version: '3'
    services:
      manager-nginx:
        build:
          context: ./manager/docker/development
          dockerfile: nginx.docker
        volumes:
          - ./manager:/app
        depends_on:
          - manager-php-fpm
        ports:
          - "80:80"
        network_mode: bridge
      manager-php-fpm:
        build:
          context: ./manager/docker/development
          dockerfile: php-fpm.docker
        volumes:
          - ./manager:/app
        network_mode: bridge
      manager-php-cli:
        build:
          context: ./manager/docker/development
          dockerfile: php-cli.docker
        volumes:
          - ./manager:/app

Nginx Error:

2020/03/31 10:49:13 [emerg] 1#1: host not found in upstream "manager-php-fpm" in /etc/nginx/conf.d/default.conf:13

php-fpm is working

[iam@localhost project-manager]$ docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "bf73901df41df980c3619a2eb9281039edd09dab4768468fa08487e3f4d248b2",
        "Created": "2020-03-30T17:47:12.591249611-04:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "c2bd5c64745af6fd2956b856418b829fd6153828f3b98dcdaae2ce81b2ea7488": {
                "Name": "project-manager_manager-php-fpm_1",
                "EndpointID": "f56886aa097f9b54711427ad58d575f756ef4d4279893a1311eaf95f165e4c65",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

The caveat of using the default docker network is that DNS resolution isn’t available. You’ll either need to replace manager-php-fpm:9000 with the IP of the container or remove network_mode: bridge so that the containers are in a user-defined network where DNS resolution is available. But then you’re back to square 0 and you need to figure out if your local network configuration is blocking internet access to that network.