简体   繁体   中英

Docker: connection refused on exposed port

I have two Docker containers: node-a, node-b. One of them (node-b) should send http request to other (node-a). I'm starting them with Docker Compose. When I'm trying to up them with Compose I face an error:

Get http://node-a:9098 : dial tcp 172.18.0.3:9098: getsockopt: connection refused

EXPOSE is declared in Docker file of a-node:

EXPOSE 9098

docker-compose.yml:

version: '3'                         
services:                            
    node-a:         
        image: a        
        ports:                       
            - 9098:9098              
        volumes:                     
            - ./:/a-src 
        depends_on:                  
            - redis                  
    node-b:            
        image: b           
        volumes:                     
            - ./:/b-src    
        depends_on:                  
            - node-a

Forwarding is enabled. I believe a server starts because it works well without Docker.

Where I should pay attention? What could cause a problem?

EDIT:

I've tried to add links but it had no effect:

node-b:            
        image: b           
        volumes:                     
            - ./:/b-src 
        links:
            - node-a   
        depends_on:                  
            - node-a

Also links seemed to be deprecated and does the same thing as depends_on in 2+ version of docker-compose.yml:

docker-compose execute V2 files, it will automatically build a network between all of the containers defined in the file, and every container will be immediately able to refer to the others just using the names defined in the docker-compose.yml file.

Link a container to the service using links . ( docker-compose documentation on links ).

Example:

node-b:            
    image: b           
    volumes:                     
        - ./:/b-src    
    depends_on:                  
        - node-a
    links:
        - node-a

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM