Accessing host's host:port from Docker container in OSX - macos

This question may be similar to other questions already answered, but I could not find any that is specific to OSX.
I'm new to Docker. I'm using Docker Version 1.12.1-beta25 (build: 11807) native support for OSX. I wanted to install a Docker Bamboo remote agent, following the instructions at https://confluence.atlassian.com/bamboo/getting-started-with-docker-and-bamboo-687213473.html. My Bamboo server is running on the host.
When running the Docker container with docker run -e HOME=/root/ -e BAMBOO_SERVER=http://hostname:port/bamboo -i -t atlassian/bamboo-java-agent:latest, it failed with Connecting to http://hostname:port/bamboo refused
The problem seems to be that the container could not access the host's http://hostname:port/bamboo. What do I need to do to get this working?

You may try to use http://172.17.0.1:port to find the host from the container. You find this address with docker inspect 'name'.
Or, you can use -p hostPort:containerPort in the docker run command and yse http://localhost:containerPort as Banboo_server

Related

Windows 10 - place docker container directly on local network?

I’ve been trying to place my container direclty on my local network (LAN). I’ve tried setting up macvlan and by using a docker but I’ve been unable to communicate directly to the container.
Here is what I’ve done:
-> Created a “macvlan” network named “pub_net” and gave it the subnet from my LAN.
I could only get the below command to be accepted by using “eth0”. Is this correct? What name is Docker expecting here?
docker network create -d macvlan \
--subnet=192.168.1.0/24 \
--gateway=192.168.1.1 -o \
parent=eth0 pub_net
Ran an image, named it “yuri”, attached it to the newly created “pub_net” network and gave it an IP from the “pub_net” subnet.
docker run -d --net=pub_net --ip=192.168.1.37 --name=yuri -t ubuntu
Once this is complete I’m unable to communicate with the container at 192.168.1.37
Any ideas what I’m doing wrong?
Thanks for any help you can give!
"The macvlan networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server."

Cannot forward ports when running Linux container on Windows10 as a host

I'm new using Docker. I have been trying to deploy a Linux container (with Windows as a host) with a Google Cloud image inside using Docker. I'm able to do everything well, at the end the server is running perfectly, but when I want to check the server, using the localhost in the browser, I got a blank page with:
Blank page
This is the Dockerfile:
FROM google/cloud-sdk
ENV PATH /usr/lib/google-cloud-sdk/bin:$PATH
WORKDIR docker_folder
COPY local_folder/ .
RUN pwd
EXPOSE 8080
CMD ["java_dev_appserver.sh", "."]
This is the command I'm using to build my image (in the CMD):
docker build --tag serverdeploy .
This is the command I'm using to run my container
docker run -p 8080:8080 serverdeploy
This is the stack trace that I got when I run the server
where I know that I running the server
I did some research and looks like Docker had a problem with the ports when you use a Linux container in Windows (Not sure if it's already solved or not). I've already tried all the possible solutions that I found out there (even trying to replace 'localhost' by all the ip's that I get when I run ipconfig on the cmd) but I still get the same error.
And, as last hope, I need your help to understand what I'm doing wrong, or if I missing something
You are running your service bind to localhost - that means no remote connections are accepted (as well as binding to 127.0.0.1. And for your container the host is a remote connection.
Change binding to 0.0.0.0 (which I guess is default) and enjoy.
Btw sharing your java_dev_appserver.sh would be helpful for answering the question.

How to include IP of Docker host in docker-compose.yml?

I want to include support for Xdebug in a PHP Docker container, however as part of this, I need to specify the IP of the Windows machine running the Docker container via XDEBUG_CONFIG=remote_host=${HOST_IP} - Currently HOST_IP is manually specified in a .env file, but I'd like to automate this to reduce the setup steps for other users.
My problem is that I can't seem to find a way to easily determine the IP of the host machine. It also needs to work on both Windows and Linux Docker hosts, as not all users use Windows as their desktop environment. I also can't use ${HOSTNAME}, as this fails to resolve in DNS.
Does anyone have any suggestions on how to achieve this?
EDIT2: Updating this answer for the newer versions of Docker: From 18.03 onward, Docker For Windows and other Docker platforms have been updated to include a cross-platform hostname for their Docker host, host.docker.internal - which is bloody helpful.
You might try a formatted docker info:
https://docs.docker.com/engine/reference/commandline/info/#format-the-output
docker info --format '{{json .}}'
docker info --format '{{json .path.to.ip}}'
E.g. in a (single-host) Docker Swarm you can get the host ip by:
docker info --format '{{json .Swarm.NodeAddr}}'
Via command substition stored in a variable:
docker_host_ip=$(docker info --format '{{json .Swarm.NodeAddr}}')
I could not try it on on Windows or on Docker without Swarm ... but docker info should work across platforms.
Update (according to comments below):
Not really (syntactically) "beautiful" you can use --format {{index path arrayIndex "Key"}} with docker network inspect and access the first element of an array (index 0) and then access the map inside this array via its key ("Gateway"):
docker network inspect docker_dockernet --format '{{index .IPAM.Config 0 "Gateway"}}'

docker deamon is not work in windows

I try to run docker in bash ubuntu on windows. But every time I get this message
"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?". If i run it in powershell - it work. Can somebody help?
Connecting to the docker deamon requires some privilidges that you don't have when starting the bash terminal.
You can however use the docker command terminal which will allow you to interact with the docker deamon.
Found the solution on this post: https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/
Connect Docker on WSL to Docker on Windows
Running docker against an engine on a different machine is actually quite easy, as Docker can expose a TCP endpoint which the CLI can attach to.
This TCP endpoint is turned off by default; to activate it, right-click the Docker icon in your taskbar and choose Settings, and tick the box next to “Expose daemon on tcp://localhost:2375 without TLS”.
With that done, all we need to do is instruct the CLI under Bash to connect to the engine running under Windows instead of to the non-existing engine running under Bash, like this:
$ docker -H tcp://0.0.0.0:2375 images
REPOSITORY TAG IMAGE ID CREATED SIZE
There are two ways to make this permanent – either add an alias for the above command, or better yet, export an environment variable which instructs Docker where to find the host engine:
$ echo "export DOCKER_HOST='tcp://0.0.0.0:2375'" >> ~/.bashrc
$ source ~/.bashrc
Now, running docker commands from Bash works just like they’re supposed to.
$ docker run hello-world
Hello from Docker!This message shows that your installation appears to be working correctly.

Connecting with JMX using Docker for Mac

I'm struggling with setting up a JMX connection to Tomcat running in a Docker container using Docker for Mac.
I think I understand the basics, and have a setenv.sh in the tomcat/bin directory looking like this:
CATALINA_OPTS="-Dcom.sun.management.jmxremote=true\
-Dcom.sun.management.jmxremote.local.only=false\
-Dcom.sun.management.jmxremote.authenticate=false\
-Dcom.sun.management.jmxremote.ssl=false\
-Djava.rmi.server.hostname=185.83.15.228\
-Dcom.sun.management.jmxremote.port=9999\
-Dcom.sun.management.jmxremote.rmi.port=9999"
I think the problematic part might be the java.rmi.server.hostname property. I've set this to the IP of the host machine, but I've also tried other obvious things. I believe this should be the IP of the machine on which jconsole or jvisualvm will be running, but this is not working for me.
I start the container like this:
docker run -d -v /Users/timbo/tomcat-jmx.sh:/usr/local/tomcat/bin/setenv.sh -p 8080:8080 -p 9999:9999 tomcat:8.0
so port 9999 is exposed.
When I try to connect using jvisualvm connecting to localhost:9999 (which Docker for Mac will route to the container which is actually on 172.17.0.2) I get the error:
Cannot connect to localhost:9999 using service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi
Any hints on what is wrong?
OK, I think I managed to find it eventually. Setting the value of java.rmi.server.hostname to the hostname of the host (e.g. mymac.local, or whatever is returned by hostname) seem to get it working. All other settings were OK.
Docker for Mac works in a bit different way. The port you map actually gets mapped to the Linux VM it is running in the background. This VM usually has in IP 192.168.99.100. So you should try and connect to 192.168.99.100:9999
To verify what is the IP of your VM, open the Docker CLI terminal and execute below
echo $DOCKER_HOST
tcp://192.168.99.100:2376

Resources