skip to Main Content

I built the jenkins service on a vm on an ubuntu system via docker run -. Now if I want to automate the image creation via jenkins & harbor configuration, I need to install docker in the jenkins container, which is used to execute the docker build command.

On my ubuntu host, I installed docker via snap install docker. which docker to see that docker is installed in /snap/bin/docker. So I used the following command while running docker run:
sudo docker run -d -p 80:8080 -p 50000:50000
-v /home/my/jenkins_home:/var/jenkins_home
-v /var/run/docker.sock:/var/run/docker.sock
-v /snap/bin/docker:/usr/bin/docker
-v /etc/docker/daemon.json:/etc/docker/daemon.json
jenkins/jenkins:lts

(Here I tried /usr/bin/docker:/usr/bin/docker and was prompted that /usr/bin/docker could not be found)
After following the above steps to create the jenkins container, I ran the docker command after entering the container via docker exec *** -it bash, only to find that the snap command was actually executed.

During my troubleshooting, I found a connection configuration on the ubuntu host via the ll /snap/bin/docker command:

$ ll /snap/bin/docker
lrwxrwxrwx 1 root root 13 Mar 27 08:51 /snap/bin/docker -> /usr/bin/snap*

Has anyone encountered this problem and is there any solution?enter image description here

2

Answers


  1. I see that you are trying to run the docker command inside the container.
    The docker command should be executed on a host, not in containers.

    Login or Signup to reply.
  2. Has anyone encountered this problem

    Yes, millions of developers before you. There are several similar questions even on this site.

    is there any solution?

    Yes, install docker inside the Jenkins container. Typically, you would create a Dockerfile that will build your Jenkins agent image.

    Strongly do not mount executable files from host. Consider not sharing configuration files from /etc/ from host with docker containers. Consider re-reading introduction to Docker, why it is used, consider interesting yourself in best practices with Docker. If you want, research docker-in-docker.

    Typically, there is jenkins controller that is only running the controller (and a minimal internal node) and jenkins-agents, and the agents have access to docker for workflows to run. Typically, agents are added the docker client, like docker not found inside jenkins pipeline or https://medium.com/@yassine.essadraoui_78000/jenkins-docker-in-docker-b7630c7b9364 or https://devopscube.com/docker-containers-as-build-slaves-jenkins/?unapproved=63874&moderation-hash=d5464a664348e998b876cdc761385caa#comment-63874 or https://rokpoto.com/jenkins-docker-in-docker-agent/ etc.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search