Setting up docker on the mac: Cannot connect via localhost

I’m just setting up docker on my Mac. The installation worked and I got some containers running (following the getting-stared guide), but now I want to connect with my browser to localhost, to show a web app.

For that I’m following this guide: https://docs.docker.com/engine/userguide/containers/usingdocker/

  • How to expose several ports for docker container?
  • Craft CMS With Php/Nginx on Docker can't write outside Document Root
  • docker node app always crashes on file change using nodemon
  • Storing in an ENV the outcome of a git command
  • Mesos/Marathon on EC2 agents hostnames not accessible
  • Why docker stops already running containers during startup?
  • In the last section it is said, that you simple go with your browser to: localhost:XXXXX wheras XXXXX is the port, that you found out using the command

    docker ps -l
    

    First problem: here nothing happends. The browser is showing an empty page (ERR_CONNECTION_REFUSED)

    Further more in the guide it is explained, that for Mac you can check your ip address via the command:

    docker-machine ip your_vm_name
    

    Here appears the second problem: This command results in an error-message:

    Host does not exist: "your_vm_name"
    

    So my questions are:

    How to set up the virtual machine (or “your_vm_name” respectively)?
    Does it have to do anything with the vhosts file on my Mac OS?
    Is there mybe a conflict with MAMP (which I’m also using sometimes)?

    Thanks in advance!

  • Singularity + Kubernetes
  • run /usr/sbin/sshd in a Dockerfile does not work
  • How to docker exec -ti CONTAINER_NAME /bin/bash on deployed docker stack?
  • Service discovery and daemons with docker
  • Kubernetes pod can't access its own service
  • Docker Swarm - Can’t pull from private registry
  • 2 Solutions collect form web for “Setting up docker on the mac: Cannot connect via localhost”

    Hello the process to start to use docker on mac with docker-machine is like:

    Create a new docker machine on virtualbox, you can use a name like “your_vm_name” or just “default” in this way you can not use the name because “default” is a keyword that docker-machine try to use when you don’t specify nothing.

    The problem here is, why docker-machine ip your_vm_name doesn’t provide the good ip? Can you copy the result of your command

    echo $DOCKER_HOST
    

    Usually it’s 192.168.99.100
    thanks a lot

    And thanks to GianArb for the very fast answer! That solution works as well.

    Just to contribute to the community, I just found out by myself, that the solution was too simple to be true.

    Instead of your-vm-name use default (obviously the default-host that is set up by docker), so I just used:

    docker-machine ip default
    

    and then I got the right IP.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.