4

I don't have a complex setup. 2 containers, one for my application and one for my API.

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                           NAMES
8f07c240bee2        nginx               "nginx -g 'daemon off"   13 hours ago        Up 13 hours         443/tcp, 0.0.0.0:7010->80/tcp   simtp_front_1
ae4296bd51d8        simtp_engine        "php-fpm"                13 hours ago        Up 13 hours         9000/tcp                        simtp_engine_1
4ae15fcba793        nginx               "nginx -g 'daemon off"   6 days ago          Up 40 hours         443/tcp, 0.0.0.0:7011->80/tcp   simtpapi_front_1
cf04c9567201        simtpapi_engine     "php-fpm"                6 days ago          Up 40 hours         9000/tcp                        simtpapi_engine_1
3da782cca9b0        mysql:5.6           "docker-entrypoint.sh"   6 days ago          Up 40 hours         0.0.0.0:3308->3306/tcp          simtpapi_db_1

I want to use Guzzle in my application to call my API, so I have linked my two containers together but when I test curl it return me :

curl: (7) Failed to connect to simtpapi port 7011: Connection refused

I can ping the container without problem:

root@ae4296bd51d8:/var/www/simtp# ping simtpapi
PING simtpapi (172.17.0.3): 56 data bytes
64 bytes from 172.17.0.3: icmp_seq=0 ttl=64 time=0.064 ms
64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.054 ms
64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.056 ms
^C--- simtpapi ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.054/0.058/0.064/0.000 ms

Here is the docker-compose file from my application:

front:
    image: nginx
    ports:
        - "7010:80"
    links:
        - "engine:engine"
    volumes:
        - ".:/var/www/simtp:ro"
        - "./docker/front/default.conf:/etc/nginx/conf.d/default.conf:ro"

engine:
    build: ./docker/engine/
    external_links:
        - "simtpapi_engine_1:simtpapi"
    volumes:
        - ".:/var/www/simtp:rw"
        - "./docker/engine/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
    working_dir: "/var/www/simtp"

And from my API:

front:
    image: nginx
    ports:
        - "7011:80"
    links:
        - "engine:engine"
    volumes:
        - ".:/var/www/simtp-api:ro"
        - "./docker/front/default.conf:/etc/nginx/conf.d/default.conf:ro"

db:
    image: mysql:5.6
    ports:
      - "3308:3306"
    environment:
      - "MYSQL_ROOT_PASSWORD=password"

engine:
    build: ./docker/engine/
    volumes:
        - ".:/var/www/simtp-api:rw"
        - "./docker/engine/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
    links:
        - "db:db"
    working_dir: "/var/www/simtp-api"

Curl version

curl 7.38.0 (x86_64-pc-linux-gnu) libcurl/7.38.0 OpenSSL/1.0.1t zlib/1.2.8 libidn/1.29 libssh2/1.4.3 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API SPNEGO NTLM NTLM_WB SSL libz TLS-SRP

Docker, Docker-machine and docker-compose

PS C:\working_directory\simtp> docker -v
Docker version 1.12.3, build 6b644ec, experimental
PS C:\working_directory\simtp> docker-machine -v
docker-machine.exe version 0.8.2, build e18a919
PS C:\working_directory\simtp> docker-compose -v
docker-compose version 1.8.1, build 004ddae

I actually use Docker for Windows (Windows 10, Developer mode and Hyper-V container enabled).

coolfarmer
  • 41
  • 1
  • 2
  • Have you resolved this? – KorbenDallas Jan 15 '19 at 13:11
  • That was a problem from long time ago, I can't answer you sorry :/ – coolfarmer Feb 03 '19 at 05:20
  • that's so frustrating – a.barbieri Jan 20 '20 at 12:06
  • I was haveing the same issue. After few hours I decided to remove (`docker stack rm `) and re-deploy (`docker stack deploy `) and everything worked. But I swear initially it didn't work. Are DNS cached somewhere? I don't know. Anyway, **removing the stack and deploying it again did it for me**. I guess it's because the container I was targeting didn't allow connection untill the server setup was completed: it definitely wasn't the first time the stack was deployed. – a.barbieri Jan 20 '20 at 16:41

1 Answers1

1

What's your curl command? You've got this in your compose file:

 ports:
        - "7011:80"

Your curl command says port 7011 is throwing connection refused, as you curling the wrong port? Make sure you're hiting port 80, as with the above directive you've mapped port 7011 -> 80 on the host.

Also, bear in mind, you've done the same in both files, so you might have both app trying to listen on port 80. To keep it simple, I'd change the ports to this respectively:

ports:
            - "7010:7010"

ports:
            - "7011:7010"
jaxxstorm
  • 606
  • 6
  • 10
  • My port should hitting port 80 in container. All works, postman work too! Only curl has problem. I hit the correct port : "curl simtpapi:7011" – coolfarmer Nov 14 '16 at 02:15
  • are you executing curl command by login to one container. If yes use port 80. and if you are doing curl from base machine use IP:7011 in curl. – Sunil Bhoi Jun 29 '18 at 09:05