I've been playing around with various docker and docker-machine tutorials. Here is the docker-machine setup

$ docker-machine ls
NAME          ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
aws-sandbox   *        amazonec2    Running   tcp://            v1.12.0
dev           -        virtualbox   Running   tcp://           v1.12.0

I understand a docker-machine to be a host where 1 or more docker containers can run. In my case I have docker-machine running on my laptop and another on EC2.

Meanwhile, I have set the EC2 instance to the default, by the following command

eval $(docker-machine env aws-sandbox)

This seems to have worked, as the aws-sandbox is marked as ACTIVE

Now I have tried to load docker containers into the docker-machine, but I am not sure if this is working.

$ docker ps
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS                          PORTS                    NAMES
fd34916854bf        orchestratingdocker_web       "env"                    About an hour ago   Restarting (0) 9 minutes ago    8000/tcp                 orchestratingdocker_web_run_2
f98b49ad026a        orchestratingdocker_web       "/usr/local/bin/pytho"   About an hour ago   Restarting (0) 23 minutes ago   8000/tcp                 orchestratingdocker_web_run_1
4d2322aa402e        orchestratingdocker_nginx     "/usr/sbin/nginx"        About an hour ago   Up About an hour      >80/tcp       orchestratingdocker_nginx_1
1b4386bcccf2        orchestratingdocker_web       "/usr/local/bin/gunic"   About an hour ago   Up About an hour                8000/tcp                 orchestratingdocker_web_1
9190ffd622ad        postgres:latest               "/docker-entrypoint.s"   About an hour ago   Up About an hour      >5432/tcp   orchestratingdocker_postgres_1
380d19e5c239        kitematic/hello-world-nginx   "sh /start.sh"           About an hour ago   Up About an hour      >80/tcp     webserver

I cannot seem to connect to any of these containers using any of:

  • localhost:8000 or 80
  • or 80
  • or 80

Do the Docker containers sit inside the docker-machine as I assume? If so, how can I list what is running inside which machine and why cannot I access the running web servers?


Yes, you are right about the containers running on the docker-machine, in this case the EC2 instance.

The most probably reason you can't connect to these is because of the default EC2 firewall rules. The default security-group created by docker-machine on AWS EC2 only allows access to SSH, Docker and possibly Swarm. (see: https://docs.docker.com/machine/drivers/aws/#/security-group)

Port 80 and 8080 are not open to the world. You'll have to log into AWS and change the security-group to allow more ports.

As a side-note, in the docker ps overview, you can see that only 3 containers are actually listening on ports, one on 80, one on 5432 and one on 8000, the others do not have port bindings to the host. For more information on this, I'd suggest reading up on docker networking and exposing ports (see: https://docs.docker.com/engine/reference/run/#/expose-incoming-ports)

  • How do I know which containers listed in docker ps are on the local docker-machine and which are on the EC2? Aug 9 '16 at 20:38
  • 1
    If you set the docker env variables (like you did with the eval $() blurb), you set which docker endpoint you're talking to. As long as those env variables are set, you're talking to that one docker endpoint (or swarm endpoint, which makes it slightly more complex). In your case all containers you see are on the EC2 instance, until you eval $(docker-machine env $someothermachine) after which you'll see the containers on $someothermachine, or unset them by eval $(docker-machine env -u) in which case docker ps will show containers on your local docker host (and not any docker-machine).
    – madeddie
    Aug 9 '16 at 20:44
  • 1
    as a extra note, you already noticed you can see which host is "active" with docker-machine ls, another one is docker-machine active. It outputs No active host found when there's no env variables set. In your case here docker info (not docker-machine), will also mention Labels: provider=amazonec2 and in case of the dev machine will probably mention provider=virtualbox
    – madeddie
    Aug 9 '16 at 20:55
  • You've been very helpful, thank you. One last point: can the docker-machine on EC2 be controlled via curl/http calls ... I'd like to launch instances using a Rails app running on Heroku Aug 9 '16 at 21:18
  • 1
    yes, with ruby I've used github.com/swipely/docker-api quite a bit, will probably do what you need and there's bound to be more projects like this.
    – madeddie
    Aug 10 '16 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.