AEM clean install -PautoInstallPackage with Jenkins in docker - docker

Situation :
I set up Jenkins with docker, to install package on AEM instance.
In my pom.xml, 'targetURL' of profile 'autoInstallPackage' is "http://localhost:4502/crx/packgmr/service.jsp".
Problem :
When I set 'targetURL' with IP address, it works.
When I set 'targetURL' with 'localohost', it fails.
What I want to do :
Run 'autoInstallPackage' targetURL with 'localhost', not IP address.
I guess the cause is this (not sure) :
Jenkins is running inside docker, so the docker container could be considered as 'localhost'.
Please help me. Thank you.

Your guess is right. The localhost exists only inside the container.
To bypass this behaviour you can run the docker image as so:
docker run --network host --name jenkins your_jenkins_image
The --network host param will cause the docker container to use the dns of the host machine (the machine running docker).

Related

gitlab running inside docker container

I have a machine with ssh running on it. Now, I wanted to run the gitlab inside the docker container. So, followed the instructions mentioned here https://docs.gitlab.com/omnibus/docker/. The instruction says bind the container ssh port 22 with host machine's ssh port(22). I was unable to do this because port was already binded with openssh server in the host machine. So I binded the container's ssh port to some other port say 222 or so. Doing so gitlab got set-up but when I try to clone the project using ssh way I am not able to do.
Is there a way to fix this issue? what could be reason, I suspect it's because of the port mapping. I want to have the ssh running on my host machine, run the gitlab inside the container and should be able to use ssh way for code commit,clone and push.
Docker port mapping is one thing but you also need to adapt the gitlab rails configuration in gitlab.rb to specify the custom ssh port :
gitlab_rails['gitlab_shell_ssh_port'] = 222
and restart the container

How to configure dynamically provisioned Docker agents

I installed Docker on Windows 10, and I pulled jenkins docker from Docker Hub. Next, I started my jenkins docker,
docker run --rm -u root -p 8080:8080 -v my_host_path:/var/jenkins_home jenkins
Next, I used Manage Jenkins and Manage Plugins to install Docker plugin, then went to the Configure page and tried to add Docker Cloud.
After I entered Docker Host URI : tcp://127.0.0.1:2375, I wanted to "Test Connection", but unfortunately got failed.
I tried to follow the instruction as below link:
How to find "Docker Host URI" to be used in Jenkins "Docker Plugin"?
But I can't not find any docker setting file under /etc/default/* in my jenkins container, so I can't set the DOCKER_OPTS argument.
Could someone give me any advise? Thank you !
Problem context: end of Chapter 3 exercise from the book "Continuous Delivery with Docker and Jenkins" by Rafal Leszko
from Configure and troubleshoot the Docker daemon page
Important: Setting hosts in the daemon.json is not supported on Docker Desktop for Windows or Docker Desktop for Mac.
Setting the docker host uri does NOT work on Windows. So either of these won't work in the Settings > Daemon tab:
"hosts" : "-H tcp://0.0.0.0:2375"
"DOCKER_OPTS" : "-H tcp://0.0.0.0:2375"
Exposing the daemon without TLS (checkbox on General tab) as recommended in some places did not work for me either.
The solution to connecting the Docker plugin in Jenkins with the docker host, is:
use the special DNS name host.docker.internal
From the docs:
How do I connect from a container to a service on the host?
Windows has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purposes and will not work in a production environment outside of Docker Desktop for Windows.
The gateway is also reachable as gateway.docker.internal.
For more information about the networking features in Docker Desktop for Windows, see Networking.
While the 'will not work in a production environment outside of Docker Desktop for Windows' disclaimer might bother some, I believe Docker for Windows is not meant for production use cases anyway.
Additionally, publish this mapping for Jenkins agent-master communication -p 50000:50000

GitLab-Runner cannot clone from local GitLab

This is my setup:
I run GitLab using Docker an expose it on port 10080 to my machine.
I have a gitlab-runner on my machine that is configured to use the Docker executor.
When I connect the runner to my GitLab instance, I use localhost:10080 as the URL which works fine.
When the runner runs a job inside a Docker container, it tries to clone the code from localhost:10080 which obviously fails since it's inside a container and localhost does not refer to my local machine.
Now what are my options? Docker for Mac has a host.docker.internal DNS entry that refers to the host machine when inside a container but I can't use it when I register the runner because the runner runs directly on my machine.
I found a solution that works for me but could depend on the system.
In ~/.gitlab-runner/config.toml under the [runners.docker] config, I just needed to add extra_hosts = ["localhost:172.17.0.1"] to override the IP for localhost. The 172.17.0.1 IP might vary on other peoples machine.

Port binding is not working in docker on windows

I have installed docker on my Windows m/c.
I am trying to install Gerrit on that.
Pull image is done-Successfully
Run image is also done -->
docker run -d -p 8080:8080 -p 29418:29418 ******/gerrit
I try to connect it through browser with my container id:8080 but it throws error
This site can’t be reached
What is oing wrong.. Please help with suggestions.
BR,
Rash
You need to access your container by IP of virtual machine. You can obtain it with command: docker-machine ls. Then access container in browser by (replace ip) http://192.168.99.100:8080
This is a known limitation of windows containers at the moment as per the docker documentation (https://docs.docker.com/docker-for-windows/troubleshoot/#limitations-of-windows-containers-for-localhost-and-published-ports).
As of Windows 10 Creator's update this has kinda been fixed where you can use host IP with the bounded host port(http://<hostIp>:<hostBoundedPort>), but still not localhost or any of it's aliases.
Alternatively you can avoid port mapping hit the container IP directly. There is numerous ways to get your container IP. Personally I would use:
docker ps
This lists out all the the running docker containers allowing you to find the Container ID for the container that you want to hit followed by:
docker inspect <initial_part_or_full_id>
This will output low level information about the container, including it's Network settings where you will find the NAT-ed endpoint details containing the IP. Then simply http://<containerIP>:<containerPort>.

Can you run Dind as a service on Tutum so that Drone can use it?

I'm new to Docker and Drone but I'm liking what I've found so far :)
Can you run Dind as a service on Tutum so that Drone can use it?
Drone CI is designed to run on a Docker host and to spin up whatever containers it needs.
It seems that drone itself can be run in a container but it must have access to the host docker daemon.
As far as I can see on Tutum you don't really have access to the docker daemon from the host.
It's possible to run drone in Dind (Docker in Docker).
But could I just run a container running Dind that I could point my drone container at via DOCKER_HOST, or am I completely misunderstanding the relationship between Drone and Docker?
It turns out you can and it all seems to work just fine :)
I have my "node" in tutum speak, which has docker running on it, but it's tutum's docker that you can interact with to some extent using their api.
Inside that I have an off the shelf dind container (docker in docker) running as a daemon with its listening port specified in the PORT environment variable (which wrapdocker picks up). That port is exposed (not publicly) using tutum's interface.
Drone is configured from another off the shelf container (for github etc) and it's linked to the dind service so that drone's DOCKER_HOST environment variable can be set to: {linked dind alias}:{port number}
...and it works :)
I feel like this should have been clear from the start but I just don't think that I believed it!

Resources