Link containers to a running container - docker

I want to know if I can link Docker containers to a running container. I am running this command on a server:
docker run -d -u jenkins --name appdev-jenkins --network=host --memory="8g" -p 80:8080 -p 443:443 -p 50000:50000 -v "/opt/jenkins":/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean
I want to be able to link another Jenkins instance as an agent to the original Jenkins instance. Is this possible?

Have you tried the following?
docker run -d --link appdev-jenkins --name second-jenkins [other params]

Related

Clickhouse cluster setup with zookpeer in Docker in Windows Machine

I created three zookeeper nodes in docker with the following commands.
docker run -d -p 2181:2181 --name zookeeper_node1 --privileged --restart always --network zoonet --ip 172.18.0.2 -v C:/zookeeper/zk_node1/volumes/data:/data -v C:/zookeeper/zk_node1/volumes/datalog:/datalog -v C:/zookeeper/zk_node1/volumes/logs:/logs -e ZOO_MY_ID=1 -e "ZOO_SERVERS=server.1=172.18.0.2:2888:3888;2181 server.2=172.18.0.3:2888:3888;2181 server.3=172.18.0.4:2888:3888;2181" 36c607e7b14d
docker run -d -p 2182:2181 --name zookeeper_node2 --privileged --restart always --network zoonet --ip 172.18.0.3 -v C:/zookeeper/zk_node2/volumes/data:/data -v C:/zookeeper/zk_node2/volumes/datalog:/datalog -v C:/zookeeper/zk_node2/volumes/logs:/logs -e ZOO_MY_ID=2 -e "ZOO_SERVERS=server.1=172.18.0.2:2888:3888;2181 server.2=172.18.0.3:2888:3888;2181 server.3=172.18.0.4:2888:3888;2181" 36c607e7b14d
docker run -d -p 2183:2181 --name zookeeper_node3 --privileged --restart always --network zoonet --ip 172.18.0.4 -v C:/zookeeper/zk_node3/volumes/data:/data -v C:/zookeeper/zk_node3/volumes/datalog:/datalog -v C:/zookeeper/zk_node3/volumes/logs:/logs -e ZOO_MY_ID=3 -e "ZOO_SERVERS=server.1=172.18.0.2:2888:3888;2181 server.2=172.18.0.3:2888:3888;2181 server.3=172.18.0.4:2888:3888;2181" 36c607e7b14d
The above three zookeeper nodes are in a network called zoonet.
I have changed the config files and started a clickhouse node in zoonet(existing in docker). I used the below command to start the clickhouse node.
docker run -d -p 8125:8123 -p 9001:9000 -p 9019:9009 --name=ck_node-1 --privileged --network zoonet --ip 172.18.0.5 --ulimit nofile=262144:262144 -v C:/some-clickhouse-server/ck-node-1/data:/var/lib/clickhouse:rw -v C:/some-clickhouse-server/ck-node-1/conf:/etc/clickhouse-server:rw -v C:/some-clickhouse-server/ck-node-1/log:/var/log/clickhouse-server:rw d846490c0466
It started the node and exited.
Can someone please help me how bring click house node into zoonet.
Thanks in Advance!
Don't try to volume clickhouse data folder -v C:/some-clickhouse-server/ck-node-1/data:/var/lib/clickhouse:rw
only logs
-v C:/some-clickhouse-server/ck-node-1/logs:/var/log/clickhouse-server/:rw
cause Windows 10 + WSL2 (I hope you use latest Docker Desktop) will mount this with 0777 rights and wrong file and folder owner, clickhouse-server will check it and fail during restart

Docker: Portainer Server vs Agent Only Deployment

I just installed Portainer CE by following Docker on Windows WSL / Docker Desktop section as shown below:
Open a terminal and run the following command:
create portainer_data
And then:
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always
-v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
Then login to the system via http://localhost:9000 without any problem (also define admin pass).
On the other hand, there is an additional section just below the second command as shown below:
Portainer Agent Only Deployment
Run the following command to deploy the Agent in your Docker host.
docker run -d -p 9001:9001 --name portainer_agent --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/volumes:/var/lib/docker/volumes portainer/agent
Is there any need to use that command and what is the benefit of Portainer Agent exactly? What is Portainer Server vs Agent Only Deployment?

Docker containers in read-only mode

still pretty new to docker and i could use some help. I am trying to setup some docker containers precisely the redash appplication. Here is my working code:
sudo docker network create redash_default
sudo docker container run --name redis --network redash_default -d redis:4.0-alpine
sudo docker container run --name postgres --network redash_default --env-file /opt/redash/env -v /opt/redash/postgres-data -d postgres:9.5.21-alpine
sudo docker container run --rm -p 5000:5000 -e REDASH_WEB_WORKERS=4 --name server --network redash_default --env-file env redash/redash:7.0.0.b18042 create_db
sudo docker container run -d --restart always -p 5000:5000 -e REDASH_WEB_WORKERS=4 --name server --network redash_default --env-file env redash/redash:7.0.0.b18042
sudo docker container run -d --restart always -e QUEUES=celery -e WORKERS_COUNT=1 --name scheduler --network redash_default --env-file env redash/redash:7.0.0.b18042
sudo docker container run -d --restart always -e QUEUES=scheduled_queries,schemas -e WORKERS_COUNT=1 --name scheduled_worker --network redash_default --env-file env redash/redash:7.0.0.b18042
sudo docker container run -d --restart always -e QUEUES=queries -e WORKERS_COUNT=2 --name adhoc_worker --network redash_default --env-file env redash/redash:7.0.0.b18042
sudo docker container run -d --restart always -p 80:80 --link server:redash --name nginx --network redash_default redash/nginx:latest
however i am only allowed to run the containers in read-only mode which is breaking the application. Only redis seemed to like the read-only mode so i thought about mounting an external persistent disk on the instance /dockervol/ where the apps can be given RW access but i cant seem to get that work either. here is something i have tried for example with nginx
docker container run -p 80:80 --mount type=bind,source=/dockervol/nginx,target=/etc/nginx – read-only --link server:redash --name nginx --network redash_default redash/nginx:latest
i get an error
nginx: [emerg] open() “/etc/nginx/nginx.conf” failed (2: No such file or directory)
My question is how do i get all the containers to work in read-only mode with a persistent volume without breaking the application.

Unable to access Docker Daemon from Jenkins

I am running Jenkins inside a docker container.
I use the following command to start the container -
docker run -p 8080:8080 -p 50000:50000 -v "${PWD}:/var/jenkins_home" -v /var/run/docker.sock:/var/run/docker.sock aemdesign/jenkins
Notice -v /var/run/docker.sock:/var/run/docker.sock - I have done this so that I can access the docker daemon from within Jenkins as per this article.
I cd into the jenkins container using docker exec -it <mycontainer> bash
I then run docker ps -a but I still get docker command not found error.
I did some more research online and found out about the docker plugin for Jenkins, and configured it to connect to the docker daemon. I get the following error
Am I missing something? How do I solve this issue? Please note that I am doing this locally on a MAC machine.
-v /var/run/docker.sock:/var/run/docker.sock, this just means your container has ability to access docker daemon on the host, not mean your container will have the docker client.
You could use -v $(which docker):/usr/bin/docker to add docker client to your container, then you will find the command.
docker run -u root -p 8080:8080 -p 50000:50000 -v $(which docker):/usr/bin/docker -v "${PWD}:/var/jenkins_home" -v /var/run/docker.sock:/var/run/docker.sock aemdesign/jenkins
Another way if you want reserve jenkins user.
docker run -u jenkins:$(cut -d: -f3 < <(getent group docker)) -p 8080:8080 -p 50000:50000 -v $(which docker):/usr/bin/docker -v "${PWD}:/var/jenkins_home" -v /var/run/docker.sock:/var/run/docker.sock aemdesign/jenkins

Can we run docker inside a docker container which is running in a virtual-box of Ubuntu 18.04?

I want to run docker inside another docker container. My main container is running in a virtualbox of OS Ubuntu 18.04 which is there on my Windows 10. On trying to run it, it is showing me as:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
How can I resolve this issue?
Yes, you can do this. Check for dind (docker in docker) on docker webpage how to achieve it: https://hub.docker.com/_/docker
Your error indicates that either dockerd in the top level container is not running or you didn't mount docker.sock on the dependent container to communicate with dockerd running on your top-level container.
I am running electric-flow in a docker container in my Ubuntu virtual-box using this docker command: docker run --name efserver --hostname=efserver -d -p 8080:8080 -p 9990:9990 -p 7800:7800 -p 7070:80 -p 443:443 -p 8443:8443 -p 8200:8200 -i -t ecdocker/eflow-ce. Inside this docker container, I want to install and run docker so that my CI/CD pipeline in electric-flow can access and use docker commands.
From your above description, ecdocker/eflow-ce is your CI/CD solution container, and you just want to use docker command in this container, then you did not need dind solution. You can just access to a container's host docker server.
Something like follows:
docker run --privileged --name efserver --hostname=efserver -d -p 8080:8080 -p 9990:9990 -p 7800:7800 -p 7070:80 -p 443:443 -p 8443:8443 -p 8200:8200 -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -i -t ecdocker/eflow-ce
Compared to your old command:
Add --privileged
Add -v $(which docker):/usr/bin/docker, then you can use docker client in container.
Add -v /var/run/docker.sock:/var/run/docker.sock, then you can access host's docker daemon using client in container.

Resources