Estimated reading time: 4 minutes
Setting up a local WordPress installation on your Mac is one of the simplest and most effective ways of turbocharging your productivity when developing.
Docker Desktop for Mac provides several networking features to make iteasier to use.
Features
VPN Passthrough
- I just started developing PHP projects on my mac (using PDT) and was wondering where localhost is located? How does Mac OS X serve websites, I haven't changed any.
- Localhost Binding by Default¶. By default, MongoDB launches with bindIp set to 127.0.0.1, which binds to the localhost network interface.This means that the mongod can only accept connections from clients that are running on the same machine. Remote clients will not be able to connect to the mongod, and the mongod will not be able to initialize a replica set unless this value is set to a.
- A quick how to guide on how to set up localhost on a Mac. This will help you create and test multiple websites locally on your computer. This is for version.
Docker Desktop for Mac's networking can work when attached to a VPN. To do this,Docker Desktop for Mac intercepts traffic from the containers and injects it intoMac as if it originated from the Docker application.
Localhost For Mac
Port Mapping
When you run a container with the -p
argument, for example:
Docker Desktop for Mac makes whatever is running on port 80 in the container (inthis case, nginx
) available on port 80 of localhost
. In this example, thehost and container ports are the same. What if you need to specify a differenthost port? If, for example, you already have something running on port 80 ofyour host machine, you can connect the container to a different port:
Now, connections to localhost:8000
are sent to port 80 in the container. Thesyntax for -p
is HOST_PORT:CLIENT_PORT
.
HTTP/HTTPS Proxy Support
See Proxies.
Known limitations, use cases, and workarounds
Following is a summary of current limitations on the Docker Desktop for Macnetworking stack, along with some ideas for workarounds.
There is no docker0 bridge on macOS
Because of the way networking is implemented in Docker Desktop for Mac, you cannot see adocker0
interface on the host. This interface is actually within the virtualmachine.
I cannot ping my containers
Docker Desktop for Mac can't route traffic to containers.
Per-container IP addressing is not possible
The docker (Linux) bridge network is not reachable from the macOS host.
Use cases and workarounds
There are two scenarios that the above limitations affect:
I want to connect from a container to a service on the host
The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS namehost.docker.internal
which resolves to the internal IP address used by thehost. This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac.
You can also reach the gateway using gateway.docker.internal
.
If you have installed Python on your machine, use the following instructions as an example to connect from a container to a service on the host:
Run the following command to start a simple HTTP server on port 8000.
python -m http.server 8000
If you have installed Python 2.x, run
python -m SimpleHTTPServer 8000
.Now, run a container, install
curl
, and try to connect to the host using the following commands:
I want to connect to a container from the Mac
Localhost For Macbook Air
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 anothercontainer. This is what you need to do even on Linux if the container is on anoverlay network, not a bridge network, as these are not routed.
The command to run the nginx
webserver shown in Getting Startedis an example of this.
Localhost For Mac
Port Mapping
When you run a container with the -p
argument, for example:
Docker Desktop for Mac makes whatever is running on port 80 in the container (inthis case, nginx
) available on port 80 of localhost
. In this example, thehost and container ports are the same. What if you need to specify a differenthost port? If, for example, you already have something running on port 80 ofyour host machine, you can connect the container to a different port:
Now, connections to localhost:8000
are sent to port 80 in the container. Thesyntax for -p
is HOST_PORT:CLIENT_PORT
.
HTTP/HTTPS Proxy Support
See Proxies.
Known limitations, use cases, and workarounds
Following is a summary of current limitations on the Docker Desktop for Macnetworking stack, along with some ideas for workarounds.
There is no docker0 bridge on macOS
Because of the way networking is implemented in Docker Desktop for Mac, you cannot see adocker0
interface on the host. This interface is actually within the virtualmachine.
I cannot ping my containers
Docker Desktop for Mac can't route traffic to containers.
Per-container IP addressing is not possible
The docker (Linux) bridge network is not reachable from the macOS host.
Use cases and workarounds
There are two scenarios that the above limitations affect:
I want to connect from a container to a service on the host
The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS namehost.docker.internal
which resolves to the internal IP address used by thehost. This is for development purpose and will not work in a production environment outside of Docker Desktop for Mac.
You can also reach the gateway using gateway.docker.internal
.
If you have installed Python on your machine, use the following instructions as an example to connect from a container to a service on the host:
Run the following command to start a simple HTTP server on port 8000.
python -m http.server 8000
If you have installed Python 2.x, run
python -m SimpleHTTPServer 8000
.Now, run a container, install
curl
, and try to connect to the host using the following commands:
I want to connect to a container from the Mac
Localhost For Macbook Air
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 anothercontainer. This is what you need to do even on Linux if the container is on anoverlay network, not a bridge network, as these are not routed.
The command to run the nginx
webserver shown in Getting Startedis an example of this.
To clarify the syntax, the following two commands both expose port 80
on thecontainer to port 8000
on the host:
To expose all ports, use the -P
flag. For example, the following commandstarts a container (in detached mode) and the -P
exposes all ports on thecontainer to random ports on the host.
See the run command for more details onpublish options used with docker run
.
By default, XAMPP has no passwords set and it is not recommended to run XAMPP with this configuration as it is accessible to others.
Simply type the following command (as root) to start a simple security check:
Localhost Ip For Mac
sudo /Applications/XAMPP/xamppfiles/xampp security
Now you should see the following dialog on your screen:
XAMPP: Quick security check...
XAMPP: MySQL is accessable via network.
XAMPP: Normaly that's not recommended. Do you want me to turn it off? [yes] yes
XAMPP: Turned off.
XAMPP: Stopping MySQL...
XAMPP: Starting MySQL...
XAMPP: The MySQL/phpMyAdmin user pma has no password set!!!
XAMPP: Do you want to set a password? [yes] yes
XAMPP: Password: ******
XAMPP: Password (again): ******
XAMPP: Setting new MySQL pma password.
XAMPP: Setting phpMyAdmin's pma password to the new one.
XAMPP: MySQL has no root passwort set!!!
XAMPP: Do you want to set a password? [yes] yes
XAMPP: Write the passworde somewhere down to make sure you won't forget it!!!
XAMPP: Password: ******
XAMPP: Password (again): ******
XAMPP: Setting new MySQL root password.
XAMPP: Setting phpMyAdmin's root password to the new one.
XAMPP: The FTP password for user 'nobody' is still set to 'lampp'.
XAMPP: Do you want to change the password? [yes] yes
XAMPP: Password: ******
XAMPP: Password (again): ******
XAMPP: Reload ProFTPD...
XAMPP: Done.
How To Find Your Localhost
(1) Setting a password will protect the XAMPP demo pages (http://localhost/xampp/) using this password. The user name is 'lampp'!
After running this command, your XAMPP installation should be more secure.