Reputation: 2359
Is there any command which we can run and find out the "Docker Host URI"? I found some of related questions but didn't get it exactly.
Upvotes: 22
Views: 38718
Reputation: 1419
to extend the discussion about Permissions from the Answer Post above
following is what I am trying to do & worked
-- I am not sure that what Im doing is proper or not
-- regarding the design of Docker_Plugin & dynamically spawn cloud Jenkins_Agent & unix:///var/run/docker.sock & Docker-in-docker problem (dind)
if what i did below is proper, keep reading
EE
with Docker DD
installedFF
-- spawned by DD
DD
as the Docker who spawns the Docker_Container with Jenkins_Agent (the Docker_Host) \
FF
(instead of Docker-in-docker) \-v /var/run/docker.sock:/var/run/docker.sock
FF
with following
docker run \
--name jenkins_main \
-p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
--restart=on-failure \
--detach \
jenkins/jenkins:lts-jdk17
Cloud jenkinsDockerAgent Configuration
> Docker Host URI
> unix:///var/run/docker.sock
Test Connection
> get Permission Deny
in ec2 instance EE
run the following command
sudo usermod -a -G docker ec2-user
(or sudo usermod -a -G docker $USER
)
in EE
, restart Docker DD
(& the Jenkins inside)
systemctl restart docker
(I can be wrong)
docker
has permission to the unix:///var/run/docker.sock
ec2-user
is the default user for ec2 instance (depends on your ami though)sudo usermod -a -G docker ec2-user
adds the ec2-user
to the group docker
ec2-user
in EE
has uid 1000
FF
there is an user called jenkins
jenkins
in FF
has the same uid 1000
as ec2-user
FF
to the outside EE
you may use sudo usermod -a -G docker $USER
$USER
returns the current user -- which is normally ec2-user
$USER
when you are root
user -- then you make a mistakeyou may instead go inside FF
& change the permission of the /var/run/docker.sock
-- so everyone can read & write to it::
docker exec -it --user root jenkins_main /bin/bash
chmod 666 /var/run/docker.sock
here is the full userdata
(bash script for ec2 start up) //TODO
EE
ec2 directly; not inside FF
which is a Docker_Container (or whatever other cases); sudo usermod -a -G docker jenkins
chmod 664 /var/run/docker.sock
From the perspective of the Docker host, any users inside the container are treated exactly the same as a user outside the container with the same UID (not the same name!), regardless of whether the UID is actually in use on the host. Unfortunately, it appears that only users with a username can belong to groups, so you can't just add the UID to the group. Instead, you need to add the host user with the same UID to the group (or create a user with that UID if one doesn't exist).
In the container, Jenkins user ID and group ID are set to 1000. The user ID as well as Docker group ID in the container, need to match on the host. This will allow Jenkins (with UID 1000) to create containers similar to how it happens on the host.
If your container doesn’t have the group
docker
, you can create it by typing this command:
Upvotes: 0
Reputation: 473
Jenkins Docker Plugin Configuration when running jenkins as container
First Install Docker Plugin.
Go to Manage Jenkins -> System Configuration -> Scroll down to botton -> Add Cloud -> Docker.
If you are running jenkins as container, in the docker host uri field you have to enter unix or tcp address of the docker host. But since you are running jenkins as container, the container can't reach docker host unix port.
So, we have to run another container that can mediate between docker host and jenkins container. It will public docker host's unix port as its tcp port. Follow the instructions to create socat container https://hub.docker.com/r/alpine/socat/
After creating the socat container, you can go back the docker configuration in jenkins and enter tcp://socat-container-ip:2375
Test Connection should succeed now.
Upvotes: 34
Reputation: 12471
If you are in the OS X, the HOST URL is:
unix:///var/run/docker.sock
Upvotes: 1
Reputation: 61
If your docker running at the same host were you use Jenkins inside a container than you can use unix:///var/run/docker.sock as the “Docker Host URI”, but you must check & obtain the permissions for jenkins user by using:
sudo groupadd docker
sudo usermod -aG docker $USER
sudo chmod a+rwx /var/run/docker.sock
sudo chmod a+rwx /var/run/docker.pid
Upvotes: 5
Reputation: 6603
Yes this is the docker host uri
tcp://127.0.0.1:2375
But before that you need to add this DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock"
In /etc/default/docker
at the end of file, then restart the docker.onec restarted docker.sock will run in 2375 and add this tcp://127.0.0.1:2375 in Jenkins
Upvotes: 12
Reputation: 405
The other option would be to enter Docker Host URI "unix: ///var/run/docker.sock", it worked for me, I hope that it is also.
Upvotes: 15