I am currently writing a small fullstack application using Docker compose, vue, and python. All my containers work in isolation, but I can't seem to get my containers to communicate using host names... Here's my code:
Docker Compose
version: "3.8"
services:
web:
build: ./TranscriptionFrontend
ports:
- 4998:4998
api:
build: ./TranscriptionAPI
Javascript Frontend Request
fetch("http://api:4999/transcribe", {
method:'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
}).then(res => {
res.json().then((json_obj) =>{
this.transcription_result = json_obj['whisper-response']
})
}).catch(e => {
this.transcription_result = "Error communicating with api: " + e;
})
I know my API service works because originally I was just mapping it to a port on my localhost, but that got messy and I want to keep access to it within my docker container. In all cases the host name could not be resolved from my JS request. Also, curl-ing from my containers using host names does provide a response i.e. docker-compose exec web curl api
or vice versa. I'm a beginner to java script and docker so apologies if I'm missing something basic.
What I've tried:
- XML Http Request
- Making call without using
http://