How to disable selinux/iptables in MacOS to visit docker server from Host computer? - macos

I am running a docker container of python server in my computer (MacOS Catalina, the container can connect MySQL and Redis from host computer, the server is running normally, but I can't visit server on host computer), in Linux environment, we need to disable the selinux, firewall and iptables, for example, edit /etc/selinux/config
and type as below
SELINUX=disabled
SELINUXTYPE=targeted
How to disable selinux/iptables in MacOS or how to visit docker server from the Host computer, I already tried to use host.docker.internal instead of 127.0.0.1, but it doesn't work, if I use host.docker.internal in MySQL or Redis config, also failed, I only can use the really IP such as 192.168.1.45 instead of host.docker.internal or 127.0.0.1

Related

Microk8s Access nginx pod to other Host Machines

I am using MIcrok8s 1.26v using Hyperv over windows 10. I am unable to access nginx pod to other host machines. I have exposed nginx using this cmd “microk8s kubectl expose deployment nginx-webserver --type=“NodePort” --port 80”. Its exposed to the clusterIP which i am able to access. What should i do to make the pod access to other host machines on the same network.
Microk8s version: 1.26v
windows version: 10 Pro
Hypervisor: HyperV
Using Multipass
I tried to access the pod with vm IP address. But was not able to access to other host machine.
Also not accessible to the host ip address where vm is deployed.
I got the solution after lots of research.
Step1: Because the IP address keeps on changing I have take this step.
To make microk8s work on DNS instead of IP Address
Edit the config file after login into microk8s-vm shell using multipass shell micrk8s-vm in cmd. Login to root user.
sudo su
vi /var/snap/microk8s/current/certs/csr.conf.template
add line >>>>>> under alt.names>>>>DNS.6 = microk8s-vm.mshome.net
exit the vim editor
Update the .kube/config and Microk8s/config . Replace the IP Address with the given dns name(eg: microk8s-vm.mshome.net)
Microk8s stop
Restart the Host machine.
Step 2: Because Microk8s port forwarding fails i have to opt for windows port forwarding.
Configure Windows port forwarding :https://woshub.com/port-forwarding-in-windows/
Now i am able to access the nginx web server on other windows machine.

Cannot access brew-installed Jenkins in VirtualBox

I installed the Jenkins through brew install jenkins-lts in macOS.
The macOS is running as VirtualBox VM instance on Windows Host.
On VirtualBox host Windows, I cannot access Jenkins through http://localhost:8080 or http://10.0.2.15:8080 from browser. (10.0.2.15 is my guest VM macOS's IP address)
What I've setup
Jenkins-lts service is started. macOS safari can access through http://localhost:8080
VirtualBox port forwarding is set, TCP/HOST: 0.0.0.0:8080 /GUEST: 10.0.2.15:8080
By the same port forwarding setup for SSH HOST: 0.0.0.0:22 /GUEST: 10.0.2.15:22, I can successfully connect to SSH.
By the default config file /usr/local/Cellar/jenkins-lts/2.x.x/homebrew.mxcl.jenkins-lts.plist. brew-installed Jenkins's default listening address is 127.0.0.1 instead of 0.0.0.0. This causes Jenkins's web server only listen request from localhost instead of any network adapter.
Steps
Edit config file, vi /usr/local/Cellar/jenkins-lts/2.x.x/homebrew.mxcl.jenkins-lts.plist
Find the row <string>--httpListenAddress=127.0.0.1</string> and change to <string>--httpListenAddress=0.0.0.0</string>
Restart Jenkins, brew services restart jenkins-lts
References
https://www.jenkins.io/doc/book/installing/, denoted httpListenAddress
https://medium.com/#vishnuteja/install-jenkins-as-a-service-on-macos-and-change-port-number-9aa097e5cfbf, denoted where brew-install Jenkins's config file.

How to access a port on the host machine when running docker container on MacOS with --network=host?

I have set up a couple of containers that interact with each other. The main application container runs on --network = host because it queries several mySQL containers running on different ports exposed on the host network.
I am trying to hit the application on the host but get an error:
curl: (7) Failed to connect to 0.0.0.0 port 36081: Connection refused
I am working on Docker installed on MacOS.
I have read several questions that indicate that docker on MacOS runs on a VM. But what is the workaround to access the application from the host? Any way to get the IP of the said VM?
You cannot use --network=host on Mac to connect via host ports but binding to host port using -p options works.
https://docs.docker.com/docker-for-mac/networking/#/there-is-no-docker0-bridge-on-osx
I WANT TO CONNECT TO A CONTAINER FROM THE MAC
Port forwarding works
for localhost; --publish, -p, or -P all work. Ports exposed from Linux
are forwarded to the host.
Our current recommendation is to publish a port, or to connect from
another container. This is what you need to do even on Linux if the
container is on an overlay network, not a bridge network, as these are
not routed.
For your use case,
You need to create a docker network and attach both the DB and application containers to this network. Then the containers will be able to talk to each other by their name. You can also publish the application container port so that you can access it from your host.
https://docs.docker.com/network/bridge/
Instead of creating the network, attaching the containers to the network etc manually, you can use docker-compose.
https://docs.docker.com/compose/

Setup ssh tunnel from docker container on macos Mojave 10.14

I am having trouble setting up an ssh tunnel on my mac machine. I have no problems setting up the tunnel on my ubuntu box. This is the command I run
ssh -nNT -L 172.18.0.1:4000:production-database-url:3306 jump-point
When I run this on my mac, I get the following error:
bind [172.18.0.1]:4000: Can't assign requested address
channel_setup_fwd_listener_tcpip: cannot listen to port: 4000 Could
not request local forwarding.
If I run without the bind_address (172.18.0.1), I am able to connect to the database via the tunnel.
If I bind to all interfaces (0.0.0.0), then tunnel is open, however, the connection to the database from inside the docker container does not work.
172.18.0.1 is the IP of docker's default bridge network gateway, not your host's IP.
You can run this command to check that.
$ docker network inspect bridge
Docker for Mac has limitations
There is no docker0 bridge on macOS (it's in the docker VM host on Mac and on Windows)
You cannot ping containers (without shaving a bunch of yaks)
Per-container IP addressing is not possible
Also note that this means the docker run option --net-host is not supported on Mac, but maybe that's a good thing
There is a workaround
These magic addresses resolve to the host's IP from within a container
docker.for.mac.localhost (deprecated)
docker.for.mac.host.internal (deprecated)
host.docker.internal
This resolves to the gateway of the host mac
gateway.docker.internal
Use the name host.docker.internal from within the container just like you would use localhost on the mac directly.
Don't worry about the bind address for the tunnel:
ssh -nNT -L 4000:production-database-url:3306 jump-point
You didn't mention which database but I take it from the port 3306 that it is MySQL.
To connect using the mysql cli from within a container, via an ssh tunnel on your host, to a remote mysql database server you can run:
mysql --host host.docker.internal [... other options go here]

Access web server over https in a Docker container

I'm using Boot2Docker to manage Docker containers in Windows and I have a container running an IBM Liberty server (I guess is the same for any other server), I can access the server home screen in the host machine using only the ip (which I get using the command boot2docker ip), but if I try to access the server using the https port, like this xx.xx.xx.xx:9443 the connection fails.
I tried forwarding the port in VirtualBox like this:
And then access the server using the ports 1000 or 1001, but it fails too.
Am I missing something?
BTW, I'm using default NAT connection.
https uses port 443 (not 9443) by default.
Make both "Host Port" and "Guest Port" 443 and try again.

Resources