Is it possible to spin up a docker instance on connection to a WiFi network?
I am looking to create sandbox environment on connection to a network and figured docker was the most suitable technology to do this.
With a native Linux install, WiFi is just another NIC to the kernel. Docker will bridge connections to this NIC without issue.
With Docker for Windows and Docker for Mac, the embedded Linux VM may need to be restarted to pickup networking changes if you change your networking environment (new DNS server, etc).
Related
Hello is it possible to access localhost in Docker and test web app on mobile device? Computer and smartphone are in the same WiFi. I would be pleased for any advice. :)
Yes, it is possible but it's not OS independency so it's good for a dev/local environment only.
Besides, it's quite vary because Docker will try to create a virtual network/adaptor on your docker machine and each different OS has their owned way and limitations.
In Window you can use docker.for.win.localhost to access host network from inside container. For MacOS, there is docker.for.mac.localhost. Docker >= 18.03 will support host.docker.internal but there is no gurantee that it will work on all platforms, so you will have to try it.
There is another safer solution and OS independent, which is using container network in host mode https://docs.docker.com/network/host/. In this mode, your container will use host machine network directly and every port exposed inside container will be exposed outside too. And of course you can access others services running on host machine by just using localhost.
I recommend you to use the docker built-in docker.for.xxx.domain if you are in dev environment and still keep the network isolation, so any security problem inside container won't affect your server. Otherwise, host mode network is a wider compatibility choice.
I’ve had a working setup with a docker-compose and especially a wildfly image running in network mode = host.
Since the company stopped the internet connection, the startup of the container is extremely slow and end with a timeout.
I found out that when I run the container in network mode = bridge, it is working just normally.
I tried with a docker-hub wildfly empty image to be sure the issue is not on my side and it’s the same problem.
It starts in 5s in bridge, and 33 in host…
I use the command :
docker run --network host jboss/wildfly:18.0.1.Final
to start the container in network host mode.
My docker version is 19.03.15 and it’s running in a VM in bridge mode.
I need the network mode host because we access the containers from outside the VM and they need to communicate with each other.
I can’t use internet anymore on the VM neither the host machine because of the security policy of the company.
So I’m looking for a solution to still use network host without this not-understandable slowness…
I’m not sure if it’s coming from wildfly or the docker itself ?
Thanks by advance,
Loïc.
I have the following setup:
Windows 10 Host (Hyper-V enabled)
Docker Desktop installed on host
VMWare Workstation Pro (16)
Windows 10 VM - Docker CLI installed on vm
The Windows 10 VM is used as a dev environment, with project-specific stuff on there.
I also use the host as a development machine for other projects - so want to be able to use docker on both.
What I'd like to do is access the docker engine running on the host, from my VM
By access docker, I mean use the docker cli to run containers, build images etc... setting DOCKER_HOST or something like that?
Is this possible? Or any other way?
So far, I've set my VM to use NAT networking and tried:
docker -H tcp://192.168.126.2:2375 images
Which returns
error during connect: Get http://192.168.126.2:2375/v1.40/images/json: dial tcp 192.168.126.2:2375: connectex: No connection could be made because the target machine actively refused it.
192.168.126.2 is the ip of the default gateway, from within the VM (so - my host?)
On the host machine, if I do docker -H tcp://0.0.0.0:2375 images I get the expected result.
On the host machine, I've also set:
"hosts": ["tcp://0.0.0.0:2375"],
within the docker engine config:
so what i would do and usually am doing is in VMware Workstation in Network editor I connect VMs to a bridge and select my main line that provides connectivity whether it is an Ethernet port or Wifi and associate it to lets say VMnet0. Then in VM settings I assign that VM's NIC to VMnet0 and that is how my VM and my host are on same LAN.
I would not use NAT.
I have an headless server with VirtualBox. It run multiple virtual machines. One of them is a web proxy. It redirect external access to the right VM in function of the subdomain. Those VMs are communicating between them with internal network (intnet).
I would like to add some docker container to this configuration. How could I successfully create a network shared between my docker containers and this proxy VM ?
I tried to create a bridge network with docker docker network create my_net and then connect the VM with a additional network card in 'bridged' mode.
With this config ping works but not the actual connection. It isn't impossible to display the web page into a browser.
Am I missing some configuration here ? Also, is it a good practice to connect one VM to a docker network ?
Run the containers on one of the VMs. Use a totally normal Docker setup here: create a network for inter-container communication but don't configure it, and completely ignore the container-private network details and IP addresses.
When you use the docker run -p option, that will publish a container's port on its VM's network interface(s). From that point, other VMs can call the published port using that VM's IP address, just as if it were a non-container process running on the VM. Conversely, containers should be able to make outbound calls to the other VMs without special setup.
I have some smart wifi devices on my network I can see from a script on my Mac. But running the same script from within a Docker container those devices are not visible.
I assume this is related to Docker for Mac's inability to connect to the host's network using --network host or network_mode: host. I also assume this issue wouldn't exist on a Linux machine but I don't have one to test on.
What is the workaround?
Edit:
Confirmed this worked fine when running inside an Ubuntu virtualbox, but I'd really not have to develop inside it.
If you start the container with network option as host, the container will share the network stack of the host. Thus any device reachable from you host should be reachable by the container.
docker run --network host ...
Adding containers to a network would allow them to communicate with each other but if you want to access other services running on host then host.docker.internal (from 18.03+). I had to do the same in a mac mini setup to access external service.
[https://docs.docker.com/docker-for-mac/networking/]
If you have to access a service on another host then you can setup an nginx server on the docker host and a proxy pass rule to direct it to the remote service.