Reputation: 85
I have a service, some-service
, that needs to make http requests to a Jenkins
service - both running in separate Docker containers. My issue is that whenever I make a request, my connection is refused.
Both some-service
and Jenkins
are running on ports 3030
and 4040
with host names some-service
and jenkins
, respectively.
I can hit Jenkins
successfully on my local machine outside of some-service
with:
curl -v http://localhost:4040/
However, I cannot reach Jenkins
from inside some-service
using:
curl -v http://jenkins:4040/
I'm using this simple Docker-compose.yaml
file to create both some-service
and Jenkins
:
version: '3'
services:
some-service:
container_name: service
image: service:latest
hostname: some-service
build:
context: service/
dockerfile: Dockerfile
environment:
GET_HOSTS_FROM: dns
networks:
- eg-net
ports:
- 3030:3030
depends_on:
- jenkins
links:
- jenkins
labels:
kompose.service.type: LoadBalancer
jenkins:
container_name: jenkins
image: jenkinsci/blueocean
restart: always
hostname: jenkins
networks:
- eg-net
ports:
- 4040:8080
volumes:
- ./jenkins-data:/var/jenkins_home
networks:
eg-net:
driver: bridge
Upvotes: 0
Views: 212
Reputation: 225
You can't access http://jenkins:4040/ from within your service because port 4040 is exposed only to the host machine. Thats why curl -v http://localhost:4040/
on your host machine works.
If you want to access jenkins from within another container you have to use the port 8080 because this port is exposed within the network. So curl -v http://jenkins:8080/
from within your service will work.
Hope this will clarify it.
Upvotes: 2