How can I run docker-compose up as shell script by Jenkins - docker

I am trying to run command docker-compose up -d as a build step of Jenkins, in "execute shell". Job fails and gives me following console log:
docker-compose up --build -d
Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
Build step 'Execute shell' marked build as failure
Finished: FAILURE`
When I cd into jenkins workspace (/var/lib/jenkins/workspace/app/) and tried to run docker-compose up, at first I could get a normal build. Right now I get error in console: ERROR: Error processing tar file(archive/tar: invalid tar header):. Of course app builds and runs normally in home directory when invoked from console.
Docker is running on host. It is possible to run docker-compose by regular user. I did add jenkins user to docker group. I even tried following some asian tutorial from http://blog.csdn.net/qiyueqinglian/article/details/46559825 that made me change DOCKER_OPTS in default/docker, but after restarting docker service it was not running on port 4243, so I didn't understood translation or it is not working on ubuntu 16.04 (host system).
Jenkins is not running in container, it is casually installed on host, no VM no docker, nothing. I tried removing docker and jenkins completly from host (purge etc) and reinstalling, still the same errors.
Any ideas?

Hit this command as a root user and try again
usermod -aG docker jenkins

Related

Set up Docker Build Step in Bamboo

I am currently despairing at the attempt of setting up a docker build step in Atlassian Bamboo.
For starters, I just want to create a build configuration that runs the hello-world image as a proof of confluence. So far, I have failed.
I have tried following the steps on https://confluence.atlassian.com/bamboo0609/using-bamboo/jobs-and-tasks/configuring-tasks/configuring-the-docker-task-in-bamboo , but to no avail.
My setup is this:
We have Bamboo installed on an Ubuntu server. I also installed Docker on that server and added the bamboo user to the docker usergroup and restarted the server to make sure the permission change takes effect. At this point, docker run hello-world works when I run it directly on the server. I can also confirm that this is the server that Bamboo runs on since Bamboo went offline whenever I restarted the server that I installed Docker on.
Then, I have added the docker capability to the server (the agent is the default agent, so it inherits this capability from the server). As the docker path, I have tried various things, none of which worked (aka, the following errors remained the same for each of these):
/snap/docker (the first folder that I found on a manual search)
/usr/bin/docker (the recommended path, though on inspecting the Ubuntu server I quickly found out that no docker folder exists under /usr/bin on the Ubuntu derver)
/var/snap/docker/common/var-lib-docker (the path that Docker returns as its Root Directory when I run docker info on the Ubuntu server)
/var/snap/docker (for good measure)
Now, for the runner, I have tried two different approaches.
First, I tried using a Docker runner with the following settings:
Command: Run a Docker container
Docker image: hello-world
This returns the following error message:
┊
Error occurred while running Task 'Hello World Docker Test(5)' of type com.atlassian.bamboo.plugins.bamboo-docker-plugin:task.docker.cli.com.atlassian.bamboo.task.TaskException: Failed to execute task
┊
Caused by: com.atlassian.bamboo.docker.DockerException: Error running Docker run command
┊
Caused by: com.atlassian.utils.process.ProcessException: Error executing /snap/docker run --volume /var/atlassian/application-data/bamboo/xml-data/build-dir/CAM-DOC-JOB1:/data --workdir /data --rm hello-world
┊
The second was just to run a shell runner for the command docker run hello-world, which returned the following error:
docker: not found
At this point, I feel like I'm out of ideas. Everything points towards Bamboo for some reason not finding Docker on the server, even though I can clearly confirm that it is there. I have tried various different approaches of telling Bamboo where to find Docker, but none of them have worked.
It's obvious that I'm doing something wrong, but I can't figure out what. Or maybe the problem lies in an entirely different direction altogether? Anyway, I would be grateful for any insight shared on this matter.
Okay, I found out what caused this strange behaviour.
The problem was that I installed Docker using sudo snap install docker, and apparently installing docker via snap causes problems with Bamboo.
So I got it to work using these simple steps:
[Server] Uninstalled Snap Docker using sudo snap remove docker
[Server] Reinstalled Docker using sudo apt install docker.io
[Bamboo] Changed the path to Docker in the Server Capabilities to /usr/bin/docker
After that, the hello-world image build succeeded and printed the expected output to the log.

Getting issue with Jenkins running as container, when executing Docker command for build images

Jenkins Docker Problem
Hello Everyone,
I installed DockerTool on Windows7. And running Jenkins in container(http://192.168.99.100:8080), and try build image via freestyle project for a POC. Seems my Jenkins is not able to execute docker command, but getting below error on build : -
"/tmp/jenkins4044405517350577133.sh: 2: /tmp/jenkins4044405517350577133.sh: docker: not found"
I have configured, Docker as Cloud in Jenkins->Configuration, but 'Docker Host URI' as tcp://192.168.99.100:2376 is not being connected, and keep running infinitely.
This value (tcp://192.168.99.100:2376), I get from executing command (docker-machine env) for DOCKER_HOST key.
command output docker-machine env
Please help me out!!!

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