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:

  • How do you run script like tasks in Docker Compose
  • Copy folder with wildcard from docker container to host
  • Docker Remote API to login to registry
  • How to deploy many instances of the same Docker image with unique database connection string
  • Fixing exited docker container
  • How to set the name of a Docker container using REST API
  • 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!

  • Passing sensitive information to Docker container in AWS EC2 container service
  • How to run docker with experimental functions on Ubuntu 16.04
  • Vagrant with Docker provider does not share folders
  • Unknown filesystem type on /dev/mapper/docker-202
  • How to work with files which belong to the subuser namespace under Linux?
  • Spark hangs on authentication with a Docker Mesos cluster
  • 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
    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.