简体   繁体   中英

Docker networking: containers not communicating

This is my docker-compose file:

version: "3.9"
services:
    api:
        image: my-api
        ports: 
            - "8090:8090"
    webapp:
        build: ./
        ports:
            - "8082:8082"

In my webapp, I have a properties file with the URL of the api service

api.url=http://api:8090/platform

The webapp code then calls the web service using that api, but it's not working. I'll get an error like this

Fail, Return Code: 404

I've tried using 'host.docker.internal' or 'docker' as well, but those don't work either. What am I doing wrong? The webapp is running in tomcat 8.5, jdk 8.

The 404 status code is an http error code that requires the connection to have succeeded. That status code came from the api container, and so you have connectivity between the containers. You should be looking at why the /platform path is not returning content in your api service.

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