0

I have this

docker-compose:

version: '3.3' services: bd_mySql: image: mysql:5.7 restart: always ports: - "3306:3306" environment: MYSQL_USER: razvan MYSQL_PASSWORD: PepitoElDeLosPalotes MYSQL_ROOT_PASSWORD: PepitoElDeLosPalotes MYSQL_DATABASE: equipojugadores api: build: data restart: always ports: - "8084:8084" python: build: python restart: on-failure depends_on: - api 

dockerfile (python)

FROM python:latest ADD scraper.py / RUN pip install BeautifulSoup4 RUN pip install html5lib RUN pip install requests RUN pip install lxml CMD [ "python", "scraper.py" ] 

Some of my python code And i have this error:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8084):

why?

5
  • Does the api container start up properly? Have you checked the logs? Commented May 24, 2019 at 16:22
  • the database and the api start.... Commented May 24, 2019 at 16:23
  • Probably not as fast as the python one does., You might wanna add some delay to the python script. Commented May 24, 2019 at 16:24
  • There is some of my scraper.py Commented May 24, 2019 at 16:28
  • Be aware that each container gets its own isolated network stack, so they each get their own IP and their own "localhost". Connecting to "localhost" in a container will (usually) never connect you to a process in another container. Take a look at docs.docker.com/compose/networking for what actually gets setup for you and how you can connect from 1 container to another Commented May 24, 2019 at 16:37

2 Answers 2

1

Your scraper.py code is trying to connect to localhost:8004, however you have placed the service that advertises port 8004 on a separate container. This is similar to if you had placed it on a separate machine, and so localhost won't reach it. Instead, you have to use api:8004, which will resolve to the IP of the api container, which is where you put this service.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, but if i want to run that docker-compose in other pc the ip gonna change, soo will not work.
docker-compose automatically makes api resolve to whatever the IP of the api container is, so it will work everywhere except when run outside of docker-compose.
0

Your py code is trying to connect with localhost for that you need provide links in python part.
After that you can call the request http://api:8084/apiname.
This worked for me:

api: build: data restart: always ports: - "8084:8084" python: build: python restart: on-failure depends_on: - api links: - api 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.