Search code examples
dockernginxdocker-containerbridgedocker-network

Docker container can't connect to other host


I have one Docker project (ASP.net web app), that wants to connect to a SQL database on another server, but its connection fails. I tried to get a ping (e.g.: google.com), but it doesn't even give a ping. I have this container in Windows and all thing work correct, but on Linux server, nothing works. For mapping, in Linux I use Nginx and map it to the Docker port. I restarted Docker Network and Docker, but it's not working. I found some tips for connecting to an internal server, but my SQL is on another server. I use 5.4.0-165-generic Ubuntu.


Solution

  • I added this line to docker.override.yml and it now works.

    dns:
      - "8.8.8.8"
    
    network_mode: bridge
    

    My docker file is now like this

    version: '3.4'
    
    services:
      redis:
        container_name: redis
        restart: always
        ports:
          - "6379:6379"
        volumes:
          - /path/to/local/dаta:/root/redis
          - /path/to/local/redis.conf:/usr/local/etc/redis/redis.conf
        environment:
          - REDIS_PASSWORD=my-password
          - REDIS_PORT=6379
          - REDIS_DATABASES=16
    
        presentation:
        environment:
          - ASPNETCORE_ENVIRONMENT=Development
        ports:
          - "6060:80"
    
    
      user.presentation:
        environment:
          - ASPNETCORE_ENVIRONMENT=Development
        ports:
          - "6065:80"
        dns:
          - "8.8.8.8"
        network_mode: bridge
      club.apigateway:
        environment:
          - ASPNETCORE_ENVIRONMENT=Development
        ports:
          - "7055:80"