Jenkins & GitLab & Docker integration fails - docker

Jenkins
In Jenkins I decided to use the remote docker feature.
So I installed docker.io on the linux server and use this pipeline.
node {
stage('Example') {
docker.withServer('tcp://docker.example.org:2375') {
docker.image('stefanscherer/node-windows:10').inside {
sh 'node --version'
}
}
}
}
But this fails with a error message about the volume configuration.
java.io.IOException: Failed to run image 'stefanscherer/node-windows:10'. Error: docker: Error response from daemon: invalid volume specification: '/var/lib/jenkins/workspace/Docker Test:/var/lib/jenkins/workspace/Docker Test:rw,z'.
See 'docker run --help'.
at org.jenkinsci.plugins.docker.workflow.client.DockerClient.run(DockerClient.java:133)
Maybe the problem is that I try to combine a linux Jenkins with a docker Windows?
But I read for this is the experimental option which should allow using Linux containers.
GitLab
GitLab-Runner installed via this guide. https://docs.gitlab.com/runner/install/windows.html
Then I connected it and selected docker as executor.
When I remove the hosts from daemon.json I get this error message.
ERROR: Preparation failed: Error response from daemon: client version 1.18 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version (executor_docker.go:1161:0s)
How to get a version which supports the newer API?
I read an article that GitLab is waiting for LTS EOL (End-of-Life). I think for CentOS or something else.
When I have the hosts set up in daemon.json I get this error message.
ERROR: Preparation failed: error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.18/info: open //./pipe/docker_engine: The system cannot find the file specified. 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. (executor_docker.go:1161:0s)
Thats because the runner can't find Docker because Docker is only listening on the TCP port.
I tried adding //./pipe/docker_engine to the hosts of daemon.json but it didn't work. The docker service is crashing immediately.
Docker
Windows Server 2016
daemon.json
{
"hosts": ["tcp://0.0.0.0:2375"],
"experimental": true
}
Goal
My goal is to build my jobs from (linux) Jenkins and (linux) GitLab on the (windows) Docker.
Problem
Jenkins is not working in general because of some settings maybe or because it tries to mount windows paths?
GitLab is expecting an old API which the docker doesn't offer.

Goal
You are in the right track, distribute your CI pipeline allows easy scalation and containers are the ideal solution for this.
Jenkins
In the Docker Pipeline Jenkins documentation it is explained:
For inside() to work, the Docker server and the Jenkins agent must use
the same filesystem, so that the workspace can be mounted.
So give a try with other command (for instance withRun) and see, in any case, I miss some credentials here. You can also configure a new Jenkins node for Docker and there you can specify the path where the jobs are executed.
GitLab
The GitLab runner issue on Windows is planned to be included in 11.8 release (Feb 2019) as it is described here.
Conclusion
I would go for a Linux installlation if you cannot wait until the new GitLab release and I would add a new Jenkins node for the docker configuration as it is described here.

Related

Jenkins build Docker container on remote host with dockerfile

I'm quite new to Jenkins and spent 2 whole days not twisting my head (and google and stackoverflow) around, how to get a docker container built on a remote host (from Jenkins host perspective).
My setup:
Docker runs on a MacOS machine (aka the "remote host")
Jenkins runs as docker container on this machine
Bitbucket Cloud runs at Atlassian
PyCharm is my development tool - running on the MacOS machine
Everything works fine so far. Now, I want Jenkins to build a docker container (on the "remote host") containing my python demo.
I'm using a dockerfile in my project:
FROM python:3
WORKDIR /usr/src/app
COPY . .
CMD ["test.py"]
ENTRYPOINT ["python3"]
I'm trying to build a jenkinsfile, I'm expecting to do 2 things
Pull the repo
Build the docker image with the help of the dockerfile on the "remote host"
Docker is installed as plugin and configured.
Docker is installed via Jenkins configuration.
Docker remote host is set up in "Cloud" setup in Jenkins - connection works (with the help of socat running as docker container)
Docker Host ist set to the remote host IP and port 2376
I'm using a jenkins pipeline project.
Most promising threat about using remote hosts is of course https://www.jenkins.io/doc/book/pipeline/docker/#using-a-remote-docker-server
But using docker.withServer('tcp://192.168.178.26:2376') (in my case, locally, no credentials because not reachable from outside), I had no luck at all.
Most common error message: hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.docker.workflow.Docker.withServer() is applicable for argument types: (java.lang.String, java.lang.String) values: [tcp://192.168.178.26:2376]
If I try to let Jenkins build it inside it's own container with its own docker, it tells me /var/jenkins_home/workspace/dockerbuild#tmp/durable-6e12255b/script.sh: 1: /var/jenkins_home/workspace/dockerbuild#tmp/durable-6e12255b/script.sh: docker: not found
Strange, as I thought, docker was installed. But I want to build at remote host anyway.
In my eyes the most promising jenkinsfile is the following - but to be honest, I am totally lost at the moment and really need some help:
node {
checkout scm
docker.withServer('tcp://192.168.178.26:2376')
def customImage = docker.build("my-image:${env.BUILD_ID}")
customImage.inside {
sh 'make test'
}
I appreciate any hint and am greatful for your help.
Best regards
Muhackl

Why doesn't TeamCity recognize docker server properties with the jetbrains/agent image?

I have an ECS Fargate service running the jetbrains/teamcity-agent image. This is connected to my TeamCity Host which is running on an EC2 instance(windows).
When I check whether the agent is capable of running docker commands, it shows the following errors:
Unmet requirements:
docker.server.osType contains linux
docker.server.version exists
Under Agent Parameters -> Configuration Parameters, I can see the docker version and the dockerCompose.version properly. Is there a setting that I am missing?
If you are trying to access a docker socket in fargate, Fargate does not support running docker commands, there is a proposed ticket for this feature.
the issue with "docker.server.osType" not showing up usually means
that the docker command run from the agent cannot connect with the
docker daemon running. This is usually due to a lack of permissions,
as docker by default only allows connections from root and users of
the group docker
Teamcity-Unmet-requirements-docker-server-osType-contains-linux
I was facing similar issues got them fixed by adding "build agent" user in "docker" group and restarted/rebooted the server.
Where build agent user ==> Means the user with which your TeamCity services are running.
Command to add a user to group
#chmod -a -G docker <userasperyourrequirement>
Command to reboot the server:
#init 6

Jenkins pipeline: docker.withServer(...) does not execute docker commands on remote server

I'm using Docker Pipeline Plugin version 1.10.
I have my Jenkins installed in a container. I have a remote server that runs a Docker daemon. The daemon is reachable from the Jenkins machine via TCP (tested). I disabled TLS security on the Docker daemon.
I'm not able to make the docker.withServer(...) step work.
As a basic test I simply put following content in a Jenkinsfile (if I'm correct this is a valid pipeline content):
docker.withServer('tcp://my.docker.host:2345') {
def myImage = docker.build('myImage')
}
When the pipeline executes I get this error: script.sh: line 2: docker: command not found like the docker command was still trying to execute locally (there is no docker command installed locally) rather than on my remote Docker daemon.
Am I missing anything ? Is it required to have the docker command installed locally when trying to execute Docker commands on a remote server..?
have you tried
withDockerServer('tcp://my.docker.host:2345') {
.....
}
Documentation here
docker needs to be installed on jenkins master in order for jenkins to be able to launch the docker on my.docker.host.
the first docker command runs on jenkins master, but with a parameter to pass the command to my.docker.host
the container itself will then run on my.docker.host
Note that you only need to install docker on the jenkins master; the daemon does not need to be running on jenkins master.
Check if you have set up port correctly. Default port for daemon is 2375. It has to be checked on both docker daemon (option -H 0.0.0.0:2375) and on the jenkins client

How to create automatic docker image after successful build of Jenkins?

I want to create a automatic docker image through Jenkins once build got success.
I tried by providing docker commands in execute shell but throwing command not found error.If this is not right way how to achieve this in Windows 10.
Error:
................
................
12 passing (81ms)
+ docker build -t snapshot .
C:\WINDOWS\TEMP\jenkins6038297422360146327.sh: line 4: docker: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Even after installing docker inside jenkins it is not picking my docker url
Docker inside jenkins
Complete error of Docker URL
Created a new vm with TLS false:
docker-machine create -d virtualbox --engine-opt tlsverify=false node2
to check TLS is made false i ran below command
docker-machine env node2
here DOCKER_TLS_VERIFY = "1",however in the documentation it is mentioned DOCKER_TLS_VERIFY = "0" should be zero whether my machine now TLS enabled or not how can i confirm my machine is TLS false??
The shell you configured in your Jenkins job is executed by Jenkins executor on Jenkins machine(or Jenkins Slave machine if you're using Jenkins the Master-Slave way), so whatever command you would like to use, it must be installed correctly and in the PATH of the target machine, just like you execute command on terminal manually.
So the error message is self-explained now:
C:\WINDOWS\TEMP\jenkins6038297422360146327.sh: line 4: docker: command not found
which means you have not installed docker on your Jenkins machine, you need to install and configure it firstly.
Additionally, you may want to have a look at Docker build step plugin for Jenkins.
install docker on jenkins. Jenkins does not know about docker.
If you don't need to run Docker on the same server than Jenkins I found that downloading a Docker Client was better than using the Jenkins Plugin.
You can find the latest version here: https://download.docker.com/win/static/stable/x86_64/
Then just call the docker command with --host 192.168.99.100. It should work and build the image on the Docker Server 192.168.99.100

Calling docker commands from jenkins job as step running outside docker VM

I want to run a docker image create command from a Jenkins job which is running native on my machine with VM running Docker.
I've installed docker build step plugin and in manage Jenkins page command fails when I try to configure docker using url and version, it says:
Test Connection Something went wrong, cannot connect to
http://192.168.99.100:2376, cause: null
I've got this docker url from the docker-machine env command.
In the version field, I tried both REST API version and Docker version, but no success.
Is it possible to call Docker from outside the docker VM and from a Jenkins job? If yes how to configure it in Jenkins?

Resources