Jenkins container is not getting connecting to remote using ssh? - docker

I have two docker container one with Jenkins and one is remote container. I want to Run a Jenkins job on remote container.
For that I have given the private keys in credentials, but still connection is not successful.
I am able to ping remote container using Jenkins container also I am able to ssh to remote container using Jenkins container.
See the screenshot below.

How are you connecting with remote host ?? Can you please share the ssh command ?
Can you please share output of below command from your Jenkins container :
cat /etc/hosts
There might be possibility that Jenkins container is able to connect using IP but not using the host_name. Try updating the the /etc/hosts file with remote container host name and then connect.
eg: 172.0.0.1 remote_host local_host
Also If you have used port forwarding, then you can simply connect with base server IP and different ports assigned to those containers.

Related

How to SSH in to different containers in Multi Container Azure App Service

I want to SSH to my containers created in an Azure App Service. These are Linux based containers and used Docker Compose to deploy these to Azure App Service.
I have followed the article to enable SSH. For one of the container (Container A) I am able to SSH (exposed port 2222, 80 for this). But I would like to SSH to other containers (Container B) too. I have exposed another port 2223 for Container B and followed the same steps in that document. When I try to access them using the command ssh root#172.xx.x.x -p 2223, I get the error Connection Refused. But the command ssh root#172.xx.x.x -p 2222 works for the Container A and I am able to see the Dotnet process running for the API in that Container A when I run the Top command
This is still not supported in 2020. For further info you can also check with GitHub repo for App Service.
https://github.com/Azure/app-service-linux-docs
For SSH in multicontainer app service, you can't select a specific container to SSH to. It's not possible as of today. Always the front-facing container is picked up for SSH which is mostly at 80 port also if not then the first container in yaml file.
https://github.com/Azure/app-service-linux-docs/blob/master/how_multicontainer_webapp_determine_web_container.md
https://feedback.azure.com/forums/169385-web-apps/suggestions/34743265-support-ssh-to-specific-container-in-multi-contain
This is the thread from product owner in late 2018. Seems like they still haven't approved that functionality.
How to SSH in to different containers in Multi Container Azure App Service
After further research, I found out that we cannot SSH to multi container. Currently Azure supports SSH to public facing container only. Based on this link its planned by Azure App Service team!

docker.sock forwarding through ssh tunnel returns "page not found"

I'm trying to access the contents of remote docker containers on a linux server from my windows machine by forwarding the remote docker socket over SSH. However, the localhost port I am forwarding it to just gives me {"message":"page not found"}, and the remote docker containers are not detected.
Ideally, I want to access the contents of the remote containers in VSCode. I've been following their walkthrough (https://code.visualstudio.com/docs/remote/containers-advanced#_option-2-connect-using-an-ssh-tunnel) on how to connect to a remote docker container. Per their walkthrough, I've also made sure to set "AllowStreamLocalForwarding yes" on the server's sshd_config
C:\Users\me> ssh -nNT -L localhost:23750:/var/run/docker.sock user#remote_server
goto http://localhost:23750/:
{"message":"page not found"}
Following the VSCode instructions:
In settings,
"docker.host":"tcp://localhost:23750"
however, clicking "Remote-Containers: Attach to a Running Container" only lists my local containers, to the server ones
I've not gotten any error messages from following these steps; however, I still don't have any access to the remote docker containers
Solved - I was entering the docker.host setting wrong on vscode
(I had entered
"docker.host":""tcp://localhost:23750""
instead of
"docker.host":"tcp://localhost:23750"
)
Sorry for spam

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

Jenkins: connection between docker container with jenkins master and docker container with jenkins slave

I run docker container with Jenkins master. I run docker container with Jenkins slave (slave image) and exposed port 8082:8080.
I created docker network to make containers see each other and it works (ping works).
I installed Docker Plugin on Jenkins master. I checked IP address of the slave container and tried to use it in the master's configuration, but master cannot connect to slave:
I think I'm doing something wrong. Any ideas what else should I do?
First check your docker daemon listening on your DockerURL and then try Testconnection
sudo dockerd
check API listening on
or provide your certs path to credential section.
certs path usually will be %userprofile%/.docker
It is throwing HttpHostConnectException because you are using tcp in the Docker URL field. Use http. Check the configuration document here.
I solved my problem.
Here is nice tutorial about setting up master in docker container and slaves aslo in docker containers. It doesn't use Docker Plugin.

Access docker remote API from container

I'm trying to access Docker remote API from within a container because I need to start other containers.
The host address is 172.19.0.1, so I'm using http://172.19.0.1:2375/images/json to get the list of images (from host, http://localhost:2375/images/json works as expected.
The connection is refused, I guess because Docker (for Windows) listens on 127.0.0.1 and not on 0.0.0.0.
I've tried to change configuration (both from UI and daemon.json) adding the entry:
"hosts": ["tcp://0.0.0.0:2375"]
but the daemon fails to start. How can I access the api?
You can set DOCKER_OPTS in windows as below and try. In Windows, Docker runs inside a VM. So, you have to ssh into the VM and make the changes.
DOCKER_OPTS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock'
Check if it works for you.
Update :- To ssh into the VM (assuming default is the VM name you have created using Docker toolbox), enter the following command in the Docker Quickstart Terminal,
docker-machine ssh default
You can find more details here.
You could link the host's /var/run/docker.sock within the container where you need it. This way, you don't expose the Docker Remote API via an open port.
Be aware that it does provide root-like access to docker.
-v /var/run/docker.sock:/var/run/docker.sock
You should use "tcp://host.docker.internal:2375" to connect to host machine from container. Please make sure that you can ping the "host.docker.internal" address
https://github.com/docker/for-win/issues/1976

Resources