Docker_Host on Jenkins with mvn fabric8:build - maven

I am trying to setup Jenkins build for my simple java microservice with Kubernetes cluster.
mvn clean package fabric8:build
I've defined DOCKER_HOST environment variable within Jenkins
DOCKER_HOST=tcp://192.168.20.1:2375
My build fails with the following error after successfully building the fat JAR
[ERROR] Failed to execute goal io.fabric8:fabric8-maven-plugin:3.5.31:build (default-cli) on project echo: Cannot create docker access object: Cannot extract API version from server http://192.168.20.1:2375 : No route to host -> [Help 1]
My Docker host runs on linux. I changed the daemon.json to add the following and restarted docker host
{
"ipv6": false ,
"live-restore": true,
"hosts" : ["tcp://192.168.20.1:2375"]
}
Still the issue persists:
Couple of questions:
Why is fabric8 resolving tcp to http? Pls looks at the error message.
What else needs to be done on Docker host to serve requests on tcp://192.168.20.1:2375?
TIA

This is purely a Docker host setup issue.
To access Docker daemon remotely, tcp socket should be enabled. More details here: https://docs.docker.com/engine/reference/commandline/dockerd/#examples
Based on our setup, I had edited the /etc/docker/daemon.json to add the "hosts" parameter
{
"ipv6": false ,
"live-restore": true,
"hosts" : ["tcp://192.168.20.1:2375"]
}
Restart docker daemon using the command
systemctl restart docker.service
Make sure docker daemon is listening to port 2375
netstat -tunlp | grep 2375
tcp 0 0 192.168.20.1:2375 0.0.0.0:* LISTEN 14648/dockerd
If after doing the above if you are still not able to access Docker daemon remotely, check if there are any firewalls that are blocking the external requests.
You can either stop them or set up a rule to allow the traffic based on your configuration.
Hope this helps

Related

docker image running not able to access api in spring boot gradle

I have created a image of spring boot gradle project by using command gradlew jibDockerBuild
I run the image by this command docker run -p 8082:8082 demo:0.0.1-SNAPSHOT.Image is running successfully on port 8082.In project application.properties server.port is 8082 only.
I am not able accesss api so I have checked in my machine whether this process is running on the port or not by command netstat -a -n -o | find "8082".No process is running on that port.
When you install Docker on Windows by Docker Toolbox by default Docker will run on 192.168.99.100 IP (DOCKER_IP).
You can access all your containers running inside docker with DOCKER_IP on your Host machine ie Windows.
Read more on it here
Regarding your mapping query
You have mapped port, which means your container port will be mapped to DOCKER_IP:PORT
If you were using Docker on Linux or Mac it will get mapped to localhost:port as in those cases Docker is running on localhost.
The same is not true for Windows at least with Docker Toolbox.
As per your configuration, you can access your application on HOST machine by hitting
http://192.168.99.100:8082

docker ports not available

I have a spring-config-sever project that I am trying to run via Docker. I can run it from the command line and my other services and browser successfully connect via:
http://localhost:8980/aservice/dev
However, if I run it via Docker, the call fails.
My config-server has a Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE=build/libs/my-config-server-0.1.0.jar
ADD ${JAR_FILE} my-config-server-0.1.0.jar
EXPOSE 8980
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/my-config-server-0.1.0.jar"]
I build via:
docker build -t my-config-server .
I am running it via:
docker run my-config-server -p 8980:8980
And then I confirm it is running via
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1cecafdf99fe my-config-server "java -Djava.securit…" 14 seconds ago Up 13 seconds 8980/tcp suspicious_brahmagupta
When I run it via Docker, the browse fails with a "ERR_CONNECTION_REFUSED" and my calling services fails with:
Could not locate PropertySource: I/O error on GET request for
"http://localhost:8980/aservice/dev": Connection refused (Connection
refused);
Adding full answer based on comments.
First, you have to specify -p before image name.
docker run -p 8980:8980 my-config-server.
Second, just configuring localhost with host port won't make your my-service container to talk to other container. locahost in container is within itself(not host). You will need to use appropriate docker networking model so both containers can talk to each other.
If you are on Linux, the default is Bridge so you can configure my-config-server container ip docker inspect {containerIp-of-config-server} as your config server endpoint.
Example if your my-config-server ip is 172.17.0.2 then endpoint is - http://172.17.0.2:8980/
spring:
cloud:
config:
uri: http://172.17.0.2:8980
Just follow the docker documentation for little bit more understanding on how networking works.
https://docs.docker.com/network/network-tutorial-standalone/
https://docs.docker.com/v17.09/engine/userguide/networking/
If you want to spin up both containers using docker-compose, then you can link both containers using service name. Just follow Networking in Compose.
I could imagine that the application only listens on localhost, ie 127.0.0.1.
You might want to try setting the property server.address to 0.0.0.0.
Then port 8980 should also be available externally.

How to publish artifact from local jenkins to local nexus - both on docker containers?

I want to publish an artifact from Jenkins on my machine to nexus on my local machine. In the future these two will have dedicated servers, but currently, for testing purposes I want to try it that way.
Jenkins and Nexus are in separate containers.
I am able to publish to nexus from my machine, running mvn clean deploy from project root directory.
I cannot do it using Jenkins.
When I enter container with Jenkins using: docker exec -it jenkins-container bash and doing curl http://localhost:8081 I receive message
curl: (7) Failed to connect to localhost port 8081: Connection refused
As I understand I need to provide different url than localhost, but which? How can I find it? How to configure it?
Your two docker containers must be on the same network. Once done, you can communicate with each other through their name that will become host :
example : curl http://{docker_container_name}:8081
See the documentation to implement a network in docker :
https://docs.docker.com/network/

Access a host from within a Docker container on Windows

I use Docker CE for Windows on latest Windows 10 and have built an image with a
script that runs a test against a web server.
(A litmus test suite for a WebDAV server to be exact, but I think the problem
is general.)
I run the web server on a Powershell console:
> wsgidav -p 8080 -H localhost
21:04:19.107 - <13348)> wsgidav INFO : Running WsgiDAV/3.0.0a3 Cheroot/6.4.0 Python/3.6.5
21:04:19.107 - <13348)> wsgidav INFO : Serving on http://localhost:8080 ...
From another Powershell console, I run my script in a Docker container (using FROM alpine).
The script starts and tries to access the endpoint, but does not succeed:
> docker pull mar10/litmus
> docker run --rm -p 8080:8080 mar10/litmus http://gateway.docker.internal:8080
-> running `basic':
0. init.................. FAIL (connection refused by `gateway.docker.internal' port 8080: Operation timed out)
I tried so far
Using the gateway.docker.internal hostname
using -p PORT:PORT
using --net=host
restarting the docker daemon (which interestingly sometimes also was neccessary to
fix timeouts in docker pull)
different IP addresses for the web server (127.0.0.1, localhost, 0.0.0.0, local IP)
Nothing worked so far (although the failure message may be different).
Maybe I just missed a working combination of the above, or any other trick?
FWIW, I was able to solve it by building the container with the --network host option and use a real IP of the client (instead of localhost or 0.0.0.0).
Details here: https://hub.docker.com/r/mar10/docker-litmus/

Connect docker container to VPN

I have a docker container from which I build and package a Java application with maven 3. I have some dependencies deployed to a Nexus server, I can only access through a VPN from local. How can I connect my docker container to that VPN?
docker image details:
Base image : Ubuntu 16.04 LTS as base system
Java 8, maven 3, Tomcat 8 installed
To create my docker container (I didn't add any network configuration):
docker run -it --rm -v '$PWD':/app -w /app/app-parent appImage/v:02 mvn clean install
And that's the error i get:
INFO: I/O exception (java.net.NoRouteToHostException) caught when processing request to {}->http://myserver:80: No route to host (Host unreachable)
May be your problem is due to DNS only.
Try resolving nexus hostname in the container's /etc/hosts file (or change maven settings.xml so that tag of nexus repository looks for the ip instead of the hostname).
To check if that is the problem, simply connect to the container
docker exec -ti yourContainer /bin/bash
then try to contact the host (depending on what you installed on the container, you could use ping, wget or other) with hostaname and ip address.

Resources