turnbullpress / dockerbook-code

The code and configuration examples from The Docker Book (http://www.dockerbook.com)
929 stars 580 forks source link

Error occur while build in jenkins #40

Closed XiaochenCui closed 5 years ago

XiaochenCui commented 7 years ago

Error in jenkins in section 5.3: Console output Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? after run sudo docker build . or docker build . The script dockerjenkins.sh seems useless now as there is none entrypoint in Dockerfile.

Actually I don't understand how you get success in the screenshot in the book.

XiaochenCui commented 7 years ago

The machine version is ubuntu 14.04, does it matters?

XiaochenCui commented 7 years ago

And I think run docker in docker is the worst idea I have seen. Since it's maddeningly and confusing. It'e better to keep it simple, stupid.

Additionally, It doesn't work in my machine.

jamtur01 commented 7 years ago

What version of the book do you have? The example no longer uses Docker-in-Docker. We now mount the Docker socket. The script exists for folks who have older versions of the book.

ChristopheBelpaire commented 7 years ago

Hello, I have problem in the build of jenkins. It seems the volume can't be correclty mounted :

jenkins@a4573d45b70a:~/jobs/Docker_test_job/workspace$ 
pwd
/var/jenkins_home/jobs/Docker_test_job/workspace
jenkins@a4573d45b70a:~/jobs/Docker_test_job/workspace$ ls
Dockerfile  Gemfile  Gemfile.lock  LICENSE  README.md  Rakefile  centos  debian  plop.txt  spec  ubuntu
jenkins@a4573d45b70a:~/jobs/Docker_test_job/workspace$ sudo docker run -ti -v /var/jenkins_home/jobs/Docker_test_job/workspace/..:/opt/project/ 884b032f6f19 /bin/bash
root@8a8fb13b03ed:/# cd /opt/project/workspace/
root@8a8fb13b03ed:/opt/project/workspace# ls -l
total 0

I'm on OSX 10.12.6 docker Docker version 17.06.0-ce, build 02c1d87

Can you help me on this ? Thanks in advance!

sspat commented 6 years ago

Same problem on Windows 10 using Docker Toolbox with Virtualbox, book version v17.12.0-ce. opt/project/workspace directory is created during mounting but is empty, build fails on rake spec Any help would be much appreciated!

sspat commented 6 years ago

Finally found the root of the problem - maybe this helps someone else stuck on chapter 5.

If you're using Windows with Docker Toolbox and use Virtualbox shared folders to mount your host directories inside the docker-machine VM to enable mounting them as volumes to your containers, then this will work:

Let's assume that instead of this step from the book:

$ sudo mkdir -p /var/jenkins_home
$ cd /var/jenkins_home
$ sudo chown -R 1000 /var/jenkins_home

We mount a host-directory from Windows to our docker machine like this:

$ vboxmanage sharedfolder add default --name "/docker_project" --hostpath "C:\work\docker" --automount

Create the jenkins image:

$ sudo docker run -d -p 8080:8080 -p 50000:50000 -v /docker_project/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --name jenkins jamtur01/jenkins

If we try to create the container for testing the build from the jenkins container like shown in the book:

CONTAINER=$(sudo docker run -d -v $MNT:/opt/project/ $IMAGE /bin/
bash -c 'cd /opt/project/workspace; rake spec')

The $MNT will point to a path inside the jenkins container, not the docker-machine VM. If we use a path from the docker-machine VM filesystem - the mount will work.

CONTAINER=$(sudo docker run -d -v /docker_project/jenkins/jobs/Docker_test_job/workspace:/opt/project/workspace $IMAGE /bin/
bash -c 'cd /opt/project/workspace; rake spec')
2yLoo commented 5 years ago

Error building project by jenkins in 5.3: Jenkins Console output: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

First, I copy the code of Dockerfile and dockerjenkins.sh from github. Then using docker command to build Jenkins(following The Docker Book). Finally I try to build my first job in Jenkins(following The Docker Book).

But I building failure in Jenkins, what's wrong with my steps?

My system version: MacOS 10.14.5 Dock Version: 18.09.2, build 6247962