Reputation: 1148
I have two python/flask services that I want to dockerize. One service s1
is the end-point for the user. The second one, s2
helps s1
. So the user calls s1
, s1
calls s2
.
How do I make it so that the ip of s2
is known to s1
? How do I do that by minimizing the amount of configuration parameters (ideally, just change only one setting)?
So far s1
:
FROM python:3-alpine
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
EXPOSE ${FLASK_RUN_ON_PORT}
CMD [ "python", "-m", "flask", "run", "--host=0.0.0.0" ]
With .env:
FLASK_ENV=production
FLASK_APP=s1.py
FLASK_RUN_PORT=5000
So far s2
:
FROM python:3-alpine
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
CMD [ "python", "-m", "flask", "run", "--host=0.0.0.0" ]
With .env:
FLASK_ENV=production
FLASK_APP=s2.py
FLASK_RUN_PORT=5050
And docker-compose as follows:
version: '3'
services:
webservice2:
build: /path/to/s2
env_file:
- /path/to/s2/.env
ports:
- ${FLASK_RUN_ON_PORT}:${FLASK_RUN_ON_PORT}
volumes:
- .:/code
webservice1:
build: /path/to/s1
env_file:
- /path/to/s1/.env
ports:
- ${FLASK_RUN_ON_PORT}:${FLASK_RUN_ON_PORT}
volumes:
- .:/code
depends_on:
- webservice2
So, to wrap up. The question is: how do I make it clear to s1
that s2
is on port 5050?
Upvotes: 0
Views: 84
Reputation: 47380
You do not do anything special.
From the docs:
Links are not required to enable services to communicate - by default, any service can reach any other service at that service’s name. (See also, the Links topic in Networking in Compose.)
Unless you do something to change the default behavior, both containers will be attached to the same network, and the host webservice1
will be known from webservice2
and viceversa.
Upvotes: 4