Docker jenkins access port - docker

I am running docker compose of jenkins image by command docker-compose up my config files
Dockerfile:
FROM java:openjdk-8-jre
EXPOSE 50000
docker-compose.yml
version: '3'
services:
jenkins:
image: jenkins:2.60.3-alpine
ports:
- 50000:50000
My container runs docker ps result:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7dbe18cdbb53 jenkins:2.60.3-alpine "/bin/tini -- /usr/l…" 22 minutes ago Up 22 minutes 8080/tcp, 0.0.0.0:50000->50000/tcp docker_jenkins_1
I checked the docker host by docker inspect 7dbe18cdbb53
Result:
],
"NetworkID": "e3a5461960939397615620f051696f8b78fde9352d0c8b42b4ed679a1e847b9b",
"EndpointID": "999b5d3525b2fe823c5ed0033bb27e85b3ca26356b4bd9f1525de005739fecde",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:02",
"DriverOpts": null
`
When i try to access from browser like 172.18.0.2:50000 it doesnt work.

The jenkins image that you have is configured to listen http traffic on port 8080.
Have a look at this: https://github.com/jenkinsci/docker/blob/c2d6f2122fa03c437e139a317b7fe5b9547fe49e/Dockerfile
This is the part where the http port default value is defined
ARG http_port=8080
and this is where it is exposed
# for main web interface:
EXPOSE ${http_port}
Similarly you can find that (slave) Agent port is 50000.
In your docker ps output you can see that the jenkins container is listening on 8080 but this is not publish on the host.
So basically you are trying to connect via http to the agent port and it is not working as expected.
Do change the docker compose file to also publish the 8080 port and use that.

Related

gocql + docker "not found"

I have a docker compose file set up like this:
version: "3"
services:
web:
image: myApp
container_name: web
environment:
CASSANDRA_HOSTS: "db"
ports:
- "8080:8080"
restart: unless-stopped
depends_on:
- cassandra
links:
- cassandra:db
cassandra:
image: cassandra
restart: unless-stopped
ports:
- "9042:9042"
expose:
- "9042"
- "7000"
- "7001"
- "9160"
volumes:
- "/private/cassandra_docker/:/var/lib/cassandra"
and when start the services up with docker-compose up -d 'web' logs:
2018/11/04 13:01:33 gocql: unable to create session: control: unable to connect to initial hosts: dial tcp 172.19.0.2:9042: connect: connection refused
2018/11/04 13:01:39 gocql: unable to dial control conn 172.19.0.2: dial tcp 172.19.0.2:9042: connect: connection refused
2018/11/04 13:01:39 could not open session with cassandra
2018/11/04 13:01:39 gocql: unable to create session: control: unable to connect to initial hosts: dial tcp 172.19.0.2:9042: connect: connection refused
2018/11/04 13:01:53 gocql: Session.handleNodeUp: 172.19.0.2:9042
2018/11/04 13:01:53 not found
2018/11/04 13:02:19 gocql: Session.handleNodeUp: 172.19.0.2:9042
2018/11/04 13:02:19 not found
when i then use docker inspect docker_cassandra_1 i see it having this ip address - so resolution works fine:
"Networks": {
"docker_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"101ae9d068ce",
"cassandra"
],
"NetworkID": "9b416bdf21c152a7d751c264b9f42799534800f08b17ada6d90ee92d62c390bc",
"EndpointID": "bc2fe3cc3fb9967e0e056d24a98b97afbc856d54f7695f8e7cfb2583a397285a",
"Gateway": "172.19.0.1",
"IPAddress": "172.19.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:13:00:02"
}
}
and in the logs of cassandra i see that the node knows what it's ip address is, and it is listening on the correct port too:
10:06:37,709 StorageService.java:2289 - Node /172.19.0.2 state jump to
NORMAL cassandra_1
INFO [main] 2018-11-04 10:06:37,737 Gossiper.java:1692 - Waiting for gossip to settle... cassandra_1
INFO [main] 2018-11-04 10:06:45,745 Gossiper.java:1723 - No gossip
backlog; proceeding cassandra_1
INFO [main] 2018-11-04
10:06:46,379 NativeTransportService.java:70 - Netty using native Epoll
event loop cassandra_1 | INFO [main] 2018-11-04 10:06:46,496
...
Starting listening for CQL clients on /0.0.0.0:9042 (unencrypted)...
when docker inspect web i see that it has no IP Address and is stuck restarting (and cannot be stopped except by force removing the image:
"Networks": {
"docker_default": {
"IPAMConfig": null,
"Links": [
"docker_cassandra_1_9415bd9be111:cassandra_1_9415bd9be111",
"docker_cassandra_1_9415bd9be111:db",
"docker_cassandra_1_9415bd9be111:docker_cassandra_1_9415bd9be111"
],
"Aliases": [
"82f1f884ee5f",
"web"
],
"NetworkID": "9b416bdf21c152a7d751c264b9f42799534800f08b17ada6d90ee92d62c390bc",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
docker ps:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82f1f884ee5f myApp "/bin/bash -c '/runA…" 6 minutes ago Restarting (1) 5 minutes ago web
b3713664e748 cassandra "docker-entrypoint.s…" 6 minutes ago Up 6 minutes 7000-7001/tcp, 7199/tcp, 9160/tcp, 0.0.0.0:9042->9042/tcp docker_cassandra_1
I also checked the system.local table in cassandra - all addresses are the correct one (the one docker dns resolves to)
what is the problem here?
EDIT.:
failed to mention: docker exec -it docker_cassandra_1 cqlsh lets me connect to the database - so it is obviously up
EDIT2:
i did some further testing and installed nmap on the myApp container (and changed it to run /bin/bash on startup instead of my entrypoint script)
this is run on the "web" container
Starting Nmap 7.60 ( https://nmap.org ) at 2018-11-04 14:13 UTC
Nmap scan report for db (172.19.0.2)
Host is up (0.000061s latency).
rDNS record for 172.19.0.2: docker_cassandra_1.docker_default
PORT STATE SERVICE
9042/tcp open unknown
MAC Address: 02:42:AC:13:00:02 (Unknown)
Nmap done: 1 IP address (1 host up) scanned in 0.47 seconds
root#028dcea32e53:/run.sh
2018/11/04 14:14:01 gocql: Session.handleNodeUp: 172.19.0.2:9042
2018/11/04 14:14:01 not found
docker exec -it docker_cassandra_1 /bin/bash
lets me connect via the external IP
csqlsh 172.19.0.2
Connected to Test Cluster at 172.19.0.2:9042.
[cqlsh 5.0.1 | Cassandra 3.11.3 | CQL spec 3.4.4 | Native protocol v4]
This is the code I connect with:
cluster := gocql.NewCluster("db")
cluster.Keyspace = "myApp"
cluster.ProtoVersion = 4
cluster.Consistency = gocql.One
var err error
DataSource.Client, err = cluster.CreateSession()
edit:
it also does not work when i start my app on the hosts and try to connect to 127.0.0.1, while port 9042 is exposed via -p 9042:9042
Open your terminal and first verify the port is already is use or not using the following command
sudo lsof -i :9042
if It is already used the you will get a list containing the process ID. You can kill the operation by using the following command
sudo kill <process ID>
After this check all the actively running docker containers by using the following command
docker ps -a
Now we can remove all the docker containers using the following command
docker rm -f $(docker ps -aq)
After all these operation use the docker compose up command that you used in your project.
docker-compose up -d
Hope it will work!

Docker - connect from HOST to container

I am using Docker for Windows with created bridge network:
"bridge":"none" (daemon.json)
docker network create --subnet 192.168.23.1/24 --gateway 192.168.23.1 --driver bridge my-network
... and container with Jenkins image.
When I configure connection between Jenkins (container) and Gitlab ("internet") everything is working fine. But when I am creating Webhook in Gitlab I have to enter URL of Jenkins. I was trying with localhost and IP obtained from IPAddress property:
"Networks": {
"my-network": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"jenkins",
"dff5dcb7c95a"
],
"NetworkID": "xxx",
"EndpointID": "yyy",
"Gateway": "192.168.23.1",
"IPAddress": "192.168.23.2",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "zzz",
"DriverOpts": null
}
}
.. but both options have been not working.
Question: How to determine correct URL?
How to connect from HOST to my container? Is it correct approach? What issues should I know to resolve following problems in the future?
Thanks for help :)
If you are running your Gitlab-instance also in a Docker-container you just need to add the Gitlab-container to the same Docker-network.
If your Gitlab-instance is really in the internet, you can not solve this with localhost or any local IP-adress. You need to:
find out your public IP-adress, maybe use dynDNS to get a fix domain if you have a dynamic IP
open a port on your router and configure your firewall
open a port on your local windows firewall
need to find out on which port jenkins is waiting for the webhooks from GitLab
map this port to the docker-container by using
--p <docker-internal-port>:<docker-external-port>
If you would provide some more information about your network infrastruture, the answer could be clearer.

cannot reach web app from docker host (not docker-machine)

I have a simple web app container running on docker engine for mac (v.1.12.5) using the following:
docker run --rm -p 80:8089 test-app
I've checked my container's IP under Networks > bridge from the following:
docker inspect $(docker ps -l --format "{{.ID}}")
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "f53f1b93aa0f2fda186498d30e7f6e5b97ba952d1b6fe442663ac6025fd74ce3",
"EndpointID": "178937cf211c2360d9f9c594891985637d1d82a334a40b1b46d3acb2ea8aaf20",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2", // <- use this?
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02"
}
}
As far as I understand, I am running my web app container on my docker engine directly on my laptop (not via docker-machine). At this point, I'm not so much concerned with making it work rather than understanding.
My container has an assigned IP 172.17.0.2 which I've pasted above and I've mapped my web app container (with an EXPOSE 80) to port 8089 via the docker run -p flag.
I'm under the impression that I should be able to reach my web app at http:// 172.17.0.2:8089 but I just get no response. Why?
If the process in the container listens on port 80, your -p flag should be the other way round -p 8089:80. The service can then be reached at localhost:8089.

Rabbitmq connection refused from Docker container to local host

I have a docker container running a java process that I am trying to connect to rabbitmq running on my localhost.
Here are the steps I've done so far:
On my Local machine (macbook running Docker version 1.13.0-rc3, build 4d92237 with firewall turned off)
I've updated my rabbitmq_env.conf file to remove RABBITMQ_NODE_IP_ADDRESS so I am not tied to connect via localhost and i have an admin rabbitmq user. (not trying with guest user)
I tested this via telnet on my local machine and have no issues telnet <local-ip> 5672
Inside my docker container
able to ping local-ip and curl rabbitmq admin api
curl -i -u username:password http://local-ip:15672/api/vhosts returns sucessfully
[{"name":"/","tracing":false}]
When i try to telnet from inside the container I get
"Connection closed by foreign host"
looking at the rabbitmq.logs
=ERROR REPORT====
closing AMQP connection <0.30526.1> (local-ip:53349 -> local-ip:5672):
{handshake_timeout,handshake}
My java stacktrace incase helpful
Caused by: java.net.ConnectException: Connection refused (Connection >refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at >java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at >java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.>java:206)
at >java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at >com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.ja>va:32)
at >com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newCon>nection(RecoveryAwareAMQConnectionFactory.java:35)
docker network inspect bridge
[
{
"Name": "bridge",
"Id": "716f935f19a107225650a95d06eb83d4c973b7943b1924815034d469164affe5",
"Created": "2016-12-11T15:34:41.950148125Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Containers": {
"9722a49c4e99ca5a7fabe56eb9e1c71b117a1e661e6c3e078d9fb54d7d276c6c": {
"Name": "testing",
"EndpointID": "eedf2822384a5ebc01e5a2066533f714b6045f661e24080a89d04574e654d841",
"MacAddress": "02:42:ac:11:00:02",
"IPv4Address": "172.17.0.2/16",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
What am I missing?
for me this works fine!
I have been installed the image docker pull rabbitmq:3-management
and run
docker run -d --hostname haroldjcastillo --name rabbit-server -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin2017 -p 5672:5672 -p 15672:15672 rabbitmq:3-management
the most important is to add the connection and management ports -p 5672:5672 -p 15672:15672
See you host in docker
docker-machine ip
return in my case:
192.168.99.100
Go to management http://192.168.99.100:15672
For Spring Boot you can configure this or works good for another connections
spring.rabbitmq.host=192.168.99.100
spring.rabbitmq.username=admin
spring.rabbitmq.password=admin2017
spring.rabbitmq.port=5672
Best wishes
For anyone else searching for this error, I'm using spring boot and rabbitmq in docker container, starting them with docker compose. I kept getting org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused from the spring app.
The rabbitmq hostname was incorrect. To fix this, I'm using the container names in the spring app configuration. Either put spring.rabbitmq.host=my-rabbit in spring's application.properties (or yml file), or in docker-compose.yaml add environment: SPRING_RABBITMQ_HOST: my-rabbit to the spring service. Of course, "my-rabbit" is the rabbitmq container name described in the docker-compose.yaml
I am using docker with linux container with rabbitmq:3-management and have created a dotnet core based web api. While calling from We API action method I faced the same issue and changed the value to "host.docker.internal"
following scenario worked for me
"localhost" on IIS Express
"localhost" on Docker build from Visual Studio
"host.docker.internal" on Docker build from Visual Studio
"Messaging": {
"Hostname": "host.docker.internal",
"OrderQueue": "ProductQueue",
"UserName": "someuser",
"Password": "somepassword" },
But facing the same issue when, the container created via docker build command, but not when container created using Visual Studio F5 command.
Now find the solution there are two ways to do it:
by default all the containers get added into "bridge" network go through with these steps
Case1: If you have already containers (rabbitmq and api) in the docker
and running then first check their ip / hostname
docker network ls
docker network inspect bridge # from this step you'll get to know what containers are associated with this
find the rabbitmq container and internal IP, apply this container name or IP and then run your application it will work from Visual Studio and Docker build and run command
Case2: if you have no containers running then you may like to create
your network in docker then follow these steps:
docker network create givenetworknamehere
add your container while using "docker run" command or after
Step2.1: if using docker run command for your container then;
docker run --network givenetworknamehere -d -p yourport:80 --name givecontainername giveyourimagename
Step2.2 if adding newly created network after container creation then use below
command docker network connect givenetworknamehere givecontainername
with these step you bring your container in your newly created same network and they can communicate.
Note: by default "bridge" network type get created
After a restart, all was working. I don't think Rabbit was using respecting .config changes

Setting Team City Build Agent Port Number in Marathon

Trying to deploy a teamcity build agent on the Mesosphere Marathon platform and having problems with the port mappings.
By default the teamcity server will try to talk to the teamcity agent on port 9090
Therefor I set the container port like so :
"containerPort": 9090
However when I deploy the teamcity agent container, Marathon maps port 9090 to a port in the 30000 range.
When teamcity server talks back to the container on port 9090 it fails because the port is mapped to 30000.
I've figured out how to get this dynamic port into the teamcity config file by running the following sed command in the marathon args :
"args": ["sh", "-c", "sed -i -- \"s/ownPort=9090/ownPort=$PORT0/g\" buildAgent.properties; bin/agent.sh run"],
When the container is spun up it will swap out ownPort=9090 for ownPort=$PORT0 in buildAgent.properties and then start the agent.
However now that the agent is on port 30000 the "containerPort": 9090 is now invalid, it should be "containerPort": $PORT0 however this is invalid json as containerPort should be an integer.
I have tried setting "containerPort": 0 which should dynamically assign a port, but using this value I cannot get the container to start it just disappears straight away and keeps trying to deploy it.
I log onto the mesos slave host and run docker ps -a I can see the containers ports are blank :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
28*********0 teamcityagent "\"sh -c 'sed -i -- 7 minutes ago Exited (137) 2 minutes ago mes************18a8
This is the Marathon json file I'm using and Marathon version is Version 0.8.2 :
{
"id": "teamcityagent",
"args": ["sh", "-c", "sed -i -- \"s/ownPort=9090/ownPort=$PORT0/g\" buildAgent.properties; bin/agent.sh run"],
"cpus": 0.05,
"mem": 4000.0,
"instances": 1,
"container":
{
"type": "DOCKER",
"docker":
{
"image": "teamcityagent",
"forcePullImage": true,
"network": "BRIDGE",
"portMappings":
[
{
"containerPort": 0,
"hostPort": 0,
"servicePort": 0,
"protocol": "tcp"
}
]
}
}
}
Any help would be greatly appreciated!
Upgrading from Marathon Version 0.8.2 to Marathon Version 0.9.0 fixed the issue, using settings "containerPort": 0, now dynamically sets a port properly and the container starts up and the teamcity server can now communicate with it.

Resources