I'm in a team where some of us use docker toolbox and some user docker desktop. We're writing an application that needs to communicate to a docker container in development.
On docker toolbox, I know the docker-machine env command sets the docker host environment variable and I can use that to get the ip of the virtual machine that's running the docker engine. From there I just access the exposed ports.
What's the equivalent way to get that information on docker desktop? (I do not have a machine that has docker desktop, only docker toolbox but I'm writing code that should be able to access the docker container on both)
On windows OS, after installed docker, there is an entry added by docker inside your hosts file (C:\Windows\System32\drivers\etc\hosts), which states the IP as:
Added by Docker Desktop
10.xx.xx.xx host.docker.internal
Below section got added in my /etc/hosts:
# Added by Docker Desktop
192.168.99.1 host.docker.internal
192.168.99.1 gateway.docker.internal
Then I was able to access by adding the port to which the app was bind to.
This command should display the IP
ping -q -c 1 docker.local | sed -En "s/^.*\((.+)\).*$/\1/p"
ipconfig can get you this information as well
Related
I am trying to create an application for a server that runs in a docker container and can be accessed over the network via an IP address. However, I can't get it to connect with anything other than localhost:port.
I am using Docker for Windows on Windows 10 with Linux Containers.
To keep it simple, I am currently trying to achieve this effect with a simple apache server.
I am using this dockerfile:
FROM ubuntu:12.04
RUN apt-get update
RUN apt-get install -y apache2
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
RUN echo 'Hello, docker' > /var/www/index.html
ENTRYPOINT ["/usr/sbin/apache2"]
CMD ["-D", "FOREGROUND"]
I can build and run it (via docker run -p 8080:80 apache-server), and access the apache server from my local windows machine's webbrowser via localhost:8080. In that case, the "hello docker"-Apache starting page is displayed, as intended.
However, I have not been able to access it using an actual IP address (other than 127.0.0.1, of course).
Addresses I tried are:
The local network address of my computer in my home network
The Subnet Address (10.0.75.0) and Mask (255.255.255.240) in the Docker for Windows Network settings
My public IP Address
None of these have worked.
Ideally, I would like to be able to access the containerized apache server from anywhere within my local network, and very ideally, I would also like to access it from outside the network.
How can I achieve this?
Edit:
I found out a way to connect to the Apache server from my local machine. Using the following Address in a web browser works: http://10.0.75.1:8080/.
If I understand it correctly, that's the subnet address.
However, I still have no idea how I can connect to the Apache-server in the container from another machine in the network. What I am looking for is for an IP address that I can input into a web browser, and that will display the "hello docker" apache-page.
I describe my doubt below:
I currently have Docker installed on my Windows computer. I have an Ubuntu 18.04 container, which has installed PHP 7.2, Apache2, and MariaDB. The port mapping is as follows:
docker run -it --name my_container -p 8080:80 -p 8081:3306 ubuntu:1804
Previously, before using Docker, I had configured a Virtual Host on my computer for a web project, something like http://my_project.dev to access it instead the typical http://localhost/projects/my_project.
Now that I changed my way of working to Docker, I have my project working perfectly on port 8080, something like this http://localhost:8080/projects/my_project, but I can't find a way to create a Virtual Host to access my project with http://mi_project.dev in my current Docker container.
I'm working with Docker to create AEM (Adobe Experience Manager) images on the basis of the following repository https://github.com/AdobeAtAdobe/aem_6-1_docker
I just can't figure out how to open a debug mode for AEM.
I have tried adding a port to EXPOSE EXPOSE 4502 30311 and adding a start file with the new JVM_OPTS CQ_JVM_OPTS="-debug -Xnoagent -Djava.compiler=none -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=30311,server=y,suspend=n ${CQ_JVM_OPTS}"
and I have also tried changing the START_OPTS START_OPTS="${START_OPTS} -debug 30311"
I'm not really comfortable with Docker yet so I'm not sure what I'm missing to startup the debug mode. Do I need to open a port in Docker via ENV or RUN?
You have to bind your host ports to container ports.
So, in your docker run add flag -p 4502:4502 -p 30311:30311
I have the following setup:
A Windows 10 Pro Laptop ("Win10Laptop") that has a Windows 10 Pro VM ("Win10VM") running on Hyper-V. I have created an nginx container by running the following command on the host machine:
docker run -d -p 80:80 --name webserver nginx
While the container is running I can access http://localhost from Win10Laptop and this works fine. My question is what do I need to configure to access nginx from Win10VM? Win10VM has only one network adaptor which is configured to use the "External" Vswitch connected to my Wifi interface.
Let me know if you need any more details. I've tried all sorts and can't figure it out!
Thanks,
Michael
You need to connect to the IP the VM has acquired on the External switch. Run ipconfig inside the VM to see what IP it has, then open http://<vm-ip> from your host.
I have used these instructions for Running Gui Apps with Docker to create images that allow me to launch GUI based applications.
It all works flawlessly when running Docker on the same machine, but it stops working when running it on a remote host.
Locally, I can run
docker --rm --ti -e DISPLAY -e <X tmp> <image_name> xclock
And I can get xclock running on my host machine.
When connecting remotely to a host with XForwarding, I am able to run X applications that show up on my local X Server, as anyone would expect.
However if in the remote host I try to run the above docker command, it fails to connect to the DISPLAY (usually localhost:10.0)
I think the problem is that the XForwarding is setup on the localhost interface of the remote host.
So the docker host has no way to connect to DISPLAY=localhost:10.0 because that localhost means the remote host, unreachable from docker itself.
Can anyone suggest an elegant way to solve this?
Regards
Alessandro
EDIT1:
One possible way I guess is to use socat to forward the remote /tmp/.X11-unix to the local machine. This way I would not need to use port forwarding.
It also looks like openssh 6.7 will natively support unix socket forwarding.
When running X applications through SSH (ssh -X), you are not using the /tmp/.X11-unix socket to communicate with the X server. You are rather using a tunnel through SSH reached via "localhost:10.0".
In order to get this to work, you need to make sure the SSH server supports X connections to the external address by setting
X11UseLocalhost no
in /etc/ssh/sshd_config.
Then $DISPLAY inside the container should be set to the IP address of the Docker host computer on the docker interface - typically 172.17.0.1. So $DISPLAY will then be 172.17.0.1:10
You need to add the X authentication token inside the docker container with "xauth add" (see here)
If there is any firewall on the Docker host computer, you will have to open up the TCP ports related to this tunnel. Typically you will have to run something like
ufw allow from 172.17.0.0/16 to any port $TCPPORT proto tcp
if you use ufw.
Then it should work. I hope it helps. See also my other answer here https://stackoverflow.com/a/48235281/5744809 for more details.