I have two different Docker containers and each has a different image. Each app in the containers uses non-conflicting ports. See the docker-compose.yml
:
version: "2"
services:
service_a:
container_name: service_a.dev
image: service_a.dev
ports:
- "6473:6473"
- "6474:6474"
- "1812:1812"
depends_on:
- postgres
volumes:
- ../configs/service_a/var/conf:/opt/services/service_a/var/conf
postgres:
container_name: postgres.dev
hostname: postgres.dev
image: postgres:9.6
ports:
- "5432:5432"
volumes:
- ../configs/postgres/scripts:/docker-entrypoint-initdb.d/
I can cURL each image successfully from the host machine (Mac OS), e.g. curl -k https://localhost:6473/service_a/api/version
works. What I'd like to do is to be able to refer to postgres
container from the service_a
container via localhost
as if these two containers were one and they share the same localhost
. I know that it's possible if I use the hostname postgres.dev
from inside the service_a
container, but I'd like to be able to use localhost
. Is this possible? Please note that I am not very well versed in networking or Docker.
Mac version: 10.12.4
Docker version: Docker version 17.03.0-ce, build 60ccb22
I have done quite some prior research, but couldn't find a solution. Relevant: https://forums.docker.com/t/localhost-and-docker-compose-networking-issue/23100/2
localhost
is only going to cause confusion. Running both processes in the same container could achieve the same without the hackiness. – Instancyservice_a
in the real world would be configured to only listen tolocalhost/127.0.0.1
. Ideally, I'd create a Docker image to have both postgres and service_a, but that didn't seem feasible, hence my approach here. – Thee