Docker remote container build over ssh - docker

I want to run every docker command on the remote host. I've set environment variable DOCKER_HOST to ssh://root#192.168.4.228
This works correctly. But every command asks for the password. Is there any way to use a ssh-key?
OS: Windows 2019 Server.
Docker: 20+.

Related

Is there any configuration to run docker inside a jenkins container?

I am trying to build an image with docker and then upload it to the docker hub, after passing the quality tests I receive the following error: docker: not found, how can I communicate my docker service (localhost) with the container of jenkins.
Important: I have docker desktop installed locally and I have installed jenkins in a local container also in windows 10 pro.
Error: https://imgur.com/q1SrKGe
Pipeline: https://imgur.com/nQWL1HR
You have 2 options to do this:
Install Docker inside your Jenkins Container and also add a bind mount for the Docker socket from your host. Otherwise your Docker Daemon inside your Container wont work. On Linux this socket is /var/run/docker.sock, so the bind mount would look like -v /var/run/docker.sock:/var/run/docker.sock.
Use a different slave agent for the Building Image Stage where you have docker installed. For e.g. you could use Docker-in-Docker (https://hub.docker.com/_/docker) as a Slave Agent for Jenkins (connected via ssh) and run your docker build inside this slave agent.

Unable to connect to local Docker host from Jenkins

I have docker installed on my Windows 10 OS on my laptop. Also I have pulled the jenkins image and created a container out of it (Image: docker pull jenkins/jenkins:latest).
My jenkins is up and running on localhost:8080. Now I have installed Docker plugin within the Jenkins and then I Add a new Cloud to run my build against docker.
However, while giving the docker host URI as "tcp://localhost:2375" it is giving me Connection Refused
Debug Steps:
I have already made by docker server listening on port 2375
I tried adding the host entry in C:\ProgramFiles\Docker\config\daemon.json
I tried adding an env variable DOCKER_HOST to "tcp://localhost:2375
But none of the above worked.
However, when I launch jenkins on my local windows machine instead of launching it from docker, it is able to resolve the Docker host URI.

Unable to connect Docker Windows Container using VNC server

I have a problem connecting a windows container I wish to use for running automation scripts.
Host - Primary Operating System which is running HyperV and docker
(Access to UI)
Target - container hosted on Host using docker (No access to UI)
Following are the details of the environment am working on:
Container image : mcr.microsoft.com/windows/servercore
Installed components include: Maven / Java / VNCServer.
Docker container is running on docker using HyperV on the same machine I wish to connect this container to.
Host Operating System is windows 10 pro.
I installed all softwares in the Target by copying them first and performing a silent installation.
I tried the following solutions but none have been possibly working out.
Started container with command : docker run -itd -p 5920:5920 --name containername imagename
Started container with command : docker start containername
Got access to cmd of Target node : docker exec -it containername cmd
Ran tasklist to ensure : vnserver was running
On Host supplied the IP address of the Target along with port numbers 5920 which results in errors stating timed out connection.
I need to be able to see the UI of the Target system and be able to
control it on the host.
Tried Commands from Teamviewer -id -p but it itself launches the UI which is not available on the Target system.
Is there a way I can get this working?
Please let me know if you need any additional information.

Openshift (oc) login to registry keeps on failing - how to start the Docker daemon?

After starting a command prompt, I normally start with login in to openshift with this command:
$ oc login https://api.starter-us-west-1.openshift.com
--token=
Works fine. Up till now I then connected to the docker registry of Openshift with the command:
$ docker login -u myOpenShiftName -p registry.starter-us-west-1.openshift.com (or :443)
Now I get this error (partly translated):
Warning: failed to get default registry endpoint from daemon (error
during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.37/info:
open //./pipe/docker_engine: The system cannot find the specified
file. In the default daemon configuration on Windows, the docker
client must be run elevated to connect. This error may also indicate
that the docker daemon is not running.). Using system default:
https://index.docker.io/v1/
Do I need a local docker running?
UPDATE/ANSWER: yes. On windows10 home start e.g. DockerQuickstartTerminal.
At another computer I had a similar error on Windows 10 pro with Docker. The service was started, but after I had started "Docker for Windows" the error disappeared.
My environment is Win10 home, virtual box + extension + docker toolbox.
The docker command cannot work without its local Docker daemon process running.
If you want to be able to work with OCI/Docker images and not need docker and the daemon, for some things you can use a tool like Skopeo.
https://github.com/containers/skopeo
There are also tools for building OCI container images which aren't dependent on docker.

Access host docker-machine from within container

I have an image that I'm using to run my CI/CD builds (using GitLab CE). I'd like to deploy my app doing something like this from within the container:
eval "$(docker-machine env manager)"
sudo docker stack deploy --compose-file docker-stack.yml web
However, I'd like the docker-machine to access machines defined on the host system since the container will be destroyed and I don't want to include access details in the image.
I've tried a few things
Accessing the Remote Host via docker-machine
Create the docker-machine on the host and mount the MACHINE_STORAGE_PATH so that it is available to the container
Connect to the remote docker-machine manually from within the container and setting the MACHINE_STORAGE_PATH equal to a mounted volume
Mounting the docker socket
In both cases, I can see the machine storage is persisted, but whenever I create a new container and run docker-machine ls none of the machines are listed.
Accessing the Remote Host via DOCKER_HOST
Forward the remote machine docker port to the host docker port docker-machine ssh manager-1 -N -L 2376:localhost:2376
export DOCKER_HOST=:2376
Tell docker to use the same certs that are used by docker-machine: export DOCKER_TLS_VERIFY=1 and export DOCKER_CERT_PATH=/Users/me/.docker/machine/machines/manager-‌​1
Test with docker info
This gives me error during connect: Get https://localhost:2376/v1.26/info: x509: certificate signed by unknown authority
Any ideas on how I can perform a remote deployment from within a container?
Thanks
EDIT
Here is a diagram to try and help better communicate the scenario.
Don't use docker-machine for this.
Docker-machine stores files in $HOME/.docker/machine, so when you restart with a fresh copy of this folder, all previously defined machines will be removed. You could store this folder as a volume, but there's a much easier way for your purposes.
The solution is to mount the docker socket, and either as root or from a user with the same gid as the docker socket (note that group names themselves inside and outside the container may not match, so gid is important), run your docker ... commands as normal. You can skip the docker-machine eval completely since you are running the commands against the local docker socket.
If you need to run commands remotely, I find it easier to define the DOCKER_HOST and DOCKER_TLS_VERIFY variables manually rather than using docker-machine.
In case you want to communicate from your CI container to the Docker host you can simply mount the Docker socket when starting the CI container:
docker run -v /var/run/docker.sock:/var/run/docker.sock <gitlab-image>
Now you can run docker commands on the host from within the CI container.

Resources