Docker in Docker dind connecting to ddev container within compose network from host maschine - docker

I'm currently working on setting up a ddev typo3 webpage running in a ubuntu dind container to get around the installation requirements for ddev on windows.
I have previously tested connecting to an nginx container within the dind container, which worked as expected. With this, nginx was served on localhost:80 on the host.
#host
docker run --rm -it --privileged -p 80:8080 ubuntu-dind
#container
docker run -it --rm -d -p 8080:80 --name web nginx
After successfully setting up and starting ddev, the following containers are now running inside my dind container:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf695c8e2ed9 drud/ddev-router:v1.21.4-built "/app/docker-entrypo…" 3 minutes ago Up 3 minutes (healthy) 127.0.0.1:80->80/tcp, 127.0.0.1:443->443/tcp, 127.0.0.1:8025-8026->8025-8026/tcp, 127.0.0.1:8036-8037->8036-8037/tcp ddev-router
6d26ecd91adf drud/ddev-webserver:20230207_fix_nvm-recruiting-built "/start.sh" 3 minutes ago Up 3 minutes (healthy) 8025/tcp, 127.0.0.1:32772->80/tcp, 127.0.0.1:32771->443/tcp ddev-recruiting-web
5e10c98eb2e7 phpmyadmin:5 "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 80/tcp ddev-recruiting-dba
8e3a5254605d drud/ddev-dbserver-mariadb-10.4:v1.21.4-recruiting-built "/docker-entrypoint.…" 3 minutes ago Up 3 minutes (healthy) 127.0.0.1:32768->3306/tcp ddev-recruiting-db
68f7527750ab drud/ddev-ssh-agent:v1.21.4-built "/entry.sh ssh-agent" 4 minutes ago Up 4 minutes (healthy) ddev-ssh-agent
The next step would now be to connect to http://recruiting.ddev.site:8036/ the site is reachable from within the dind container, but im unsure of how to connect to this address from the host.
I have fired up my dind container as follows:
docker run --rm -it --privileged -v ${PWD}/project:/usr/src/project -p 80:8036 dindu
Attempting to map port 8036 of the container to port 80 on the host.
Testing to connect to port 8036 inside the container reaches:
root#57fcae15337a:/usr/src/project# curl 127.0.0.1:8036
<!DOCTYPE html>
<html>
<head>
<title>503: No ddev back-end site available</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>503: No ddev back-end site available.</h1>
<p>This is the ddev-router container: There is no back-end webserver at the URL you specified. You may want to use "ddev start" to start the site.</p>
</body>
</html>
And only gets an ERR_EMPTY_RESPONSE from the host, so it's there have to be some additional steps im missing. I don't believe my problem is ddev specific and has more to do with me being somewhat inexperienced with docker networking.
How do I forward an address, like http://recruiting.ddev.site, instead of a simple port to the host machine?

Related

mix link docker containers with network

I have the following setup:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eab42051ca26 web-www:20180804 "node run.js" 8 minutes ago Up 8 minutes 3000/tcp web-www
63ec48e93a77 jwilder/nginx-proxy:latest "/app/docker-entrypo…" 9 hours ago Up 9 hours 0.0.0.0:80->80/tcp nginx-proxy-server
463ffd55260b fiorix/freegeoip "/go/bin/freegeoip" 9 hours ago Up 9 hours 8080/tcp freegeoip
bdc702c370ec euvat "/usr/local/bin/euva…" 9 hours ago Up 9 hours 3000/tcp euvat
40c07de732fa redis:4.0.10 "docker-entrypoint.s…" 9 hours ago Up 9 hours 6379/tcp redis-www
76831834f59d mongo:4.0 "docker-entrypoint.s…" 9 hours ago Up 9 hours 27017/tcp mongo-www
where my web-www node.js app connects to redis and mongo via the
NETWORK ID NAME DRIVER SCOPE
74d8f38aca38 bridge bridge local
1c894a7fa176 host host local
ca02c5ccac55 network-www bridge local
7226d9cc5360 none null local
my run.sh file is like:
OLDAPP="$(docker ps --all --quiet --filter=name="$APP")"
if [ -n "$OLDAPP" ]; then
docker stop $OLDAPP && docker rm $OLDAPP
fi
docker run --name web-www \
--network network-www \
--link euvat:euvat \
--link freegeoip:freegeoip \
--env VIRTUAL_HOST=araweelo.local \
--env-file /env/web-www.env \
web-www:20180804.182446
so, now i am starting a new development stack dev-www for example, so i will create the network-dev, launch redis-dev and mongo-dev but want to share the euvat and freegeoip containers with the web-www container.
is this the correct way to do this or is there an alternative method?
any advice is much appreciated.
Docker links are deprecated and maybe removed soon.
It's better to create the networks, containers ahead of time and join the container to the network
docker network create network-www
docker run --name web-www \
--env VIRTUAL_HOST=araweelo.local \
--env-file /env/web-www.env \
web-www:20180804.182446
docker network connect network-www web-www
docker network connect network-www euvat
docker network connect network-www freegeoip
This above commands will create a network-www user-defined bridge network and connect euvat, web-www and freegeoip containers to that network.
Replace/add containers as required. Might be a better idea to write a compose file which brings up the containers in a single command

map internal port 80 to localhost port 80 in docker

I had ran the docker image and it is showing the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cbcc0a6d5c1e programming_applicationserver "bin/wait-for-it.sh …" About an hour ago Up About an hour 0.0.0.0:80->80/tcp, 5436/tcp programming_applicationserver_run_3
4cb5bdbb6c1d programming_onlineaccountverifier "bin/wait-for-it.sh …" 5 days ago Up About an hour 127.0.0.1:5435->5435/tcp programming_onlineaccountverifier_1
bf39ba383cec programming_onlineballotregulator "bin/docker_entrypoi…" 5 days ago Up About an hour 8545/tcp, 127.0.0.1:5434->5434/tcp, 30303/tcp programming_onlineballotregulator_1
but when I go to localhost:80 nothing is shown.
What should I do now ?
This is likely due to an error in the application itself and not docker.
To verify that, you can go into the container and make sure the application is port is working reachable:
docker exec -it programming_applicationserver_run_3 bash
Once you are inside the container, try accessing the port using one of the following command:
curl localhost:80
wget localhost:80
If non of these are successful, this would imply that the problem is related to the application and not to docker itself.

Connect to a Service running inside a docker container from outside

I have a service running in a docker container (local machine). I can see the service URL in the Ambari service config.
Now I want to connect to that service using my local development environment.
I found I can connect to that within the container but when I use that URL outside in my local I get connection refused.
Cause: org.apache.http.conn.HttpHostConnectException: Connect to
xx.xx.xx.com:12008 [xx.xx.xx.com/195.169.98.101] failed: Connection refused
How to connect to a service running inside a container from outside?
In my case code execute in my local machine.
If your container has mapped its port on the VM 12008 port, you would need to make sure you have port forwarded 12008 in your VirtualBox connection settings, as I mention in "How to connect mysql workbench to running mysql inside docker?"
VBoxManage controlvm "boot2docker-vm" --natpf1 "tcp-port12008 ,tcp,,12008,,12008"
VBoxManage controlvm "boot2docker-vm" --natpf1 "udp-port12008 ,udp,,12008,,12008"
The question needs more clarification, but I will answer with some assumptions.
I used an Ambari docker image (chose this randomly based on popularity).
Then I started 3 clusters as mentioned and my amb-settings and docker ps looked like this:
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ amb-settings
NODE_PREFIX=amb
CLUSTER_SIZE=3
AMBARI_SERVER_NAME=amb-server
AMBARI_SERVER_IMAGE=hortonworks/ambari-server:latest
AMBARI_AGENT_IMAGE=hortonworks/ambari-agent:latest
DOCKER_OPTS=
AMBARI_SERVER_IP=172.17.0.6
CONSUL=amb-consul
CONSUL_IMAGE=sequenceiq/consul:v0.5.0-v6
EXPOSE_DNS=false
DRY_RUN=false
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2483a74d919 hortonworks/ambari-agent:latest "/usr/sbin/init syste" 20 minutes ago Up 20 minutes amb2
4acaec766eaa hortonworks/ambari-agent:latest "/usr/sbin/init syste" 21 minutes ago Up 20 minutes amb1
47e9419de59f hortonworks/ambari-server:latest "/usr/sbin/init syste" 21 minutes ago Up 21 minutes 8080/tcp amb-server
548730bb1824 sequenceiq/consul:v0.5.0-v6 "/bin/start -server -" 22 minutes ago Up 22 minutes 53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 8301-8302/udp, 8500/tcp amb-consul
27c725af6531 sequenceiq/ambari "/usr/sbin/init" 23 minutes ago Up 23 minutes 8080/tcp awesome_tesla
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$
As of now, I can visit the Ambari server through: http://172.17.0.6:8080/
This works also from my host computer. However, if you want this to be connected from another computer from a similar network, then one option is to have a haproxy which does the redirection from:
localhost:8080 -> 172.17.0.6:8080
So, I created a small haproxy.cfg and Dockerfile to achieve this:
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ cat Dockerfile
FROM haproxy:1.6
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ cat haproxy.cfg
frontend localnodes
bind *:8080
mode http
default_backend ambari
backend ambari
mode http
server ambari-server 172.17.0.6:8080 check
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ docker build --rm -t ambariproxy .
Sending build context to Docker daemon 9.635 MB
Step 1 : FROM haproxy:1.6
---> af749d0291b2
Step 2 : COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
---> Using cache
---> 60cdd2c7bb05
Successfully built 60cdd2c7bb05
anovil#anovil-Latitude-E6440:~/tmp/docker-ambari$ docker run -d -p 8080:8080 ambariproxy
63dd026349bbb6752dbd898e1ae70e48a8785e792b35040e0d0473acb00c2834
Now if I say localhost:8080 or MY_HOST_IP:8080 I can see the ambari-server and this should work also from computers in the same network.
Hope I managed to answer your question :)
Thanks,

binding of ports not working in docker

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2047cd997469 q1 "/bin/bash" 2 hours ago Up 2 hours **8001/tcp, 0.0.0.0:8001->9001/tcp** wicket1
ddb02ced5a0b q2 "/bin/bash" 28 hours ago Up 2 hours 0.0.0.0:8080->8080/tcp tender_fermi
3966528ee466 q3 "/start.sh -D FOREGR 5 days ago Up 3 hours 0.0.0.0:3306->3306/tcp
As you can see I have three docker images running everything is working fine except for the image q1 I am not able to run through the port 9001 ..says connection refused. what may be the possible reason. application is working fine inside the container.
below is the port command:
sudo docker port 2047cd997469
9001/tcp -> 0.0.0.0:8001
Are you using vagrant or boot2docker? If need to connect 8001 port on your virtual machine. For the boot2docker, you can use boot2docker ip to get the ip. For the vagrant, you can use vagrant ssh to login and get the ip.

Docker: multi kafka brokers failed

I would like to use docker with several kafka brokers.
So I started some tests with this docker image => https://github.com/ches/docker-kafka
For one broker all work fine:
I start my zookeeper:
docker run -d --name zookeeper jplock/zookeeper:3.4.6
Then I start a kafka instance:
docker run -d --name kafka --link zookeeper:zookeeper ches/kafka
When I create topic and messages, all work.
Now I create a second kafka instance:
docker run -d --name kafka2 --link zookeeper:zookeeper --expose 9093 --env-file env ches/kafka
I change the exposed port to 9093 and environment variables:
PORT=9093
EXPOSED_PORT=9093
BROKER_ID=2
The broker starts well and I can create a topic with replication:
docker -D run --rm ches/kafka kafka-topics.sh --create --topic test2 --replication-factor 2 --partitions 1 --zookeeper $ZK_IP:2181
Now when I want to send some messages:
docker run --rm --interactive ches/kafka kafka-console-producer.sh --topic test2 --broker-list $KAFKA_IP:9092
I get this error:
ERROR Producer connection to 172.17.0.17:9093 unsuccessful
(kafka.producer.SyncProducer) java.net.ConnectException: Connection
refused
A docker ps give me that:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d7bba0f3d0db ches/kafka:latest "kafka-console-produ About a minute ago Up About a minute 9092/tcp, 7203/tcp sick_shockley
9c475a659383 ches/kafka:latest "/start.sh" 4 minutes ago Up 4 minutes 7203/tcp, 9092/tcp, 9093/tcp kafka2
63aae4c539ab ches/kafka:latest "/start.sh" 28 minutes ago Up 28 minutes 7203/tcp, 9092/tcp kafka
ab560690e0e7 jplock/zookeeper:3.4.6 "/opt/zookeeper/bin/ 28 minutes ago Up 28 minutes 2181/tcp, 2888/tcp, 3888/tcp zookeeper
So kafka2 seems started on 9093 port.
Why I get this error ?
Thanks.
Check in the zookeeper docker what is the advertised host name of the kafka dockers. It's very possible that they registered their docker hash as host name (as it's the result of getInetAdress() within a docker container) instead of a resolvable address.
If that's the case, editing your standard kafka config to change advertised.host.name should solve your problem (it's a bit annoying because you have to change it at start, but you can for example fetch it from the /etc/hosts file of the docker container at startup, it should be the first half of the first line in it).

Resources