After the mac installs docker, follow official documentation to operate docker-machine to create a local vm
$ docker-machine create --driver virtualbox default
$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default - virtualbox Running tcp://192.168.99.102:2376 v18.05.0-ce
Add to environment
$ docker-machine env default export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.102:2376" export DOCKER_CERT_PATH="/Users/xushuainan/.docker/machine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval $(docker-machine env default)
Connect to environment
eval "$(docker-machine env default)"
$ docker-machine ip default 192.168.99.102
Create a nginx
docker run -d -p 8000:80 nginx
$curl $(docker-machine ip default):8000 curl: (7) Failed to connect to 192.168.99.102 port 8000: Connection refused
Why is this? ? ?
Previously, mysql was also created in docker. mysql can be used when connected to the inside of the container, but it cannot be accessed from outside through ip in vm.
Ask the great god for guidance.
Naturally, the ip of the docker-machine pile of virtual machines is the ip that they communicate with each other. If you don’t believe you can enter one of the virtual machines, then see if you can ping the nginx service of the other machine.
Then you need to make these virtual machines into a cluster. My side is the Swarm cluster, and then you can run the service, and then you can host the port corresponding to the container internal port or something.