X-post from https://groups.google.com/forum/#!topic/docker-user/A180aHSlQRE
Let's say I run following command to link web container to db container-
docker run -d -P --name web --link db training/webapp python app.py
Now I want my web container to be linked to additional container WITHOUT restarting web container. Is it possible?
No, once started you can't link the container to another container. But you can link a new container to the web container:
docker run -d -P --name myapp --link web <image> <command>
or you can link another web container to the db container:
docker run -d -P --name web2 --link db training/webapp python app.py
Having said that since your first web container is running you can also run:
docker inspect web
to find out the details of that container and see if you'd like to use them in your new container that you create. Another thing you can try is to make your web container interactive so once you started it you can modify it at runtime.
Actually, there is way to overcome this limitation.
What you can do in this situation is to add LINKED_CONTAINER_IP and LINKED_CONTAINER_NAME directly into /etc/hosts file of "HOST CONTAINER" using following procedure:
get the IP address of the running container which you want additionally to link into "host container" using
docker inspect --format '{{ .NetworkSettings.IPAddress }}' CONTAINERID
directly from host
3 then add that ip with the name into /etc/hosts of "HOST CONTAINER" file as following
first get interactive access into shall of running host container
docker exec -it CONTAINERID sh
once you get into shell prompt add line to /etc/hosts file using
echo "LINKED_CONTAINER_IP LINKED_CONTAINER_NAME" >> /etc/hosts
verify using ping LINKED_CONTAINER_NAME
Please note this is temporary solution which works only until any of containers are restarted in which case IP address may change and therefore resolving to LINKED_NAME will not work any more!
Related
I'm running a Java web application on a Docker cluster running those commands:
PS C:\Users\Marco\test_workspace> docker run -v test_web_application.war:/usr/local/tomcat/webapps/TestWebApplication.war -it -p 8080:8080 --network "host" -d Tomcat
The actual output confirms that the container is running:
At this point i want to access to the container through it's IP address from my host and i'm using the command inspect to identify the IP:
But, as the screenshot shows, i don't see any IP assigned.
Thus, my questions are:
Why the command --network "host" to assign an IP address shared with the host didn't worked ?
Finally, how can i access to my web application from the host ?
Command option --network="host" isn't supported for Docker for Windows (more information: https://docs.docker.com/network/host/).
You can access your application on localhost:8080 with launch option -p 8080:8080.
I want to setup a rancher server and a rancher agent on the same server.
Here is what i have done for creating server:
docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable
Then, I have opened my web-browser on 8080 port.
I have chosen a login/password and enabled access control.
Then i wanted to create a host (agent). Rancher web interface says me to type this command:
docker run -e CATTLE_AGENT_IP=x.x.x.x --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.10 http://nsxxx.ovh.net:8080/v1/scripts/yyyy:1514678400000:zzzz
I have no error message, but I do not see any entry in host section (in rancher web interface).
So I tried to execute a shell on the agent docker container:
docker exec -ti xxxxx /bin/bash
I tried to manually run run.sh script and here is what I see:
Error: No such image or container: nsxxx
I suppose this is because docker containers cannot communicate together, but I have done exactly what is in the documentation...
Thanks for your help
For docker exec your need to replace the xxxxx string with the container id or the name of the container. Both you get from the docker ps command
So I've created a container for RabbitMq with the following command.
docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3-management
Which works fine, but I then created another container with the following command
docker run test .
This runs a container with a PHP file that tries to connect to the hostname, my-rabbit but it can't find it the host so the PHP just closes itself right away. I did, however, find out the IP of the my-rabbit( first container ) and replace the hostname( my-rabbit ) in my PHP code with the IP and it connects with no problems.
So how do I create a hostname for the RabbitMq that all the other container on the same network can see and use instead of an IP?
I found out the answer after making this post. I use the --link arg with docker run.
https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#communication-across-links
I have found a similar thread, but failed to get it to work. So, the use case is
I start a container on my Linux host
docker run -i -t --privileged -p 8080:2375 mattgruter/doubledocker
When in that container, I want to start another one with GAE SDK devserver running.
At that, I need to access a running app from the host system browser.
When I start a container in the container as
docker run -i -t -p 2375:8080 image/name
I get an error saying that 2375 port is in use. I start the app, and can curl 0.0.0.0:8080 when inside both containers (when using another port 8080:8080 for example) but cannot preview the app from the host system, since lohalhost:8080 listens to 2375 port in the first container, and that port cannot be used when launching the second container.
I'm able to do that using the image jpetazzo/dind. The test I have done and worked (as an example):
From my host machine I run the container with docker installed:
docker run --privileged -t -i --rm -e LOG=file -p 18080:8080
jpetazzo/dind
Then inside the container I've pulled nginx image and run it with
docker run -d -p 8080:80 nginx
And from the host environment I can browse the nginx welcome page with http://localhost:18080
With the image you were using (mattgruter/doubledocker) I have some problem running it (something related to log attach).
We can create a new container and define your application port in docker run command like
sudo docker run -d -p 5000:5000 training/webapp python app.py
or
sudo docker run -d -P training/webapp python app.py
But, what if someone forgot to specify -p or -P option in docker run command? The container get created and runs the application locally. Now how could I assign a port on which application is running locally in container to the port of my Ubuntu host machine?
Kindly, help on this.
Thanks.
Short: You can't. You need to stop the container (or not) and start a new one with the proper parameters.
Docker spins up a local proxy and setup the iptables for proper NAT. If you really can't start a new container, you could manually setup the iptables and spin up a socat. You can take a look at the network part of the Docker code for more info.