On my development machine, I am trying to make a docker container connect to a mysql server on the host. To do this, I have set the networking mode to "host" like so:
phpfpm:
image: mageinferno/magento2-php:7.0.8-fpm-0
container_name: php7fpm
restart: always
hostname: phpfpm
ports:
- "9000:9000"
environment:
- APP_MAGE_MODE=developer
volumes:
- /Users:/Users
- /usr/local/var/log/nginx:/var/www/logs
net: "host"
The problem is that after I start the docker container, I can't telnet to localhost 9000 from the host. Connecting to the container on 9000 is not a problem when the container runs in bridge mode. The docker ps command shows:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6de4c973a34a mageinferno/magento2-php:7.0.8-fpm-0 "/usr/local/bin/start" 4 seconds ago Up 3 seconds php7fpm
Why doesn't the container bind the ports to the host? What am I missing here?
I am on OS X 10.10 using Docker for Mac (Version 1.12.0-rc3-beta18 (build: 9996))
Is there a reason you are trying to use host networking? It can be a bit tricky to set up and is mostly for pretty special use cases. At a minimum, you need to make sure the Docker host allows that port via something like:
iptables -I INPUT 1 -p tcp -m tcp --dport 9000 -j ACCEPT
Otherwise you are probably better sticking with bridge mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With