0

I'm trying to map a port from my container, to a port on the host following the docs but it doesn't appear to be working.

After I run docker-compose -f development.yml up --force-recreate I get no errors. But if I try to reach the frontend service using localhost:8081 the network is unreachable.

I used docker inspect to view the IP and tried to ping that and still nothing.

Here is the docker-compose file I am using. And I doing anything wrong?

development.yml

version: '3'
services:
  frontend:
    image: nginx:latest
    ports:
      - "8081:80"
    volumes:
      - ./frontend/public:/var/www/html
  api:
    image: richarvey/nginx-php-fpm:latest
    ports:
      - "8080:80"
    restart: always
    volumes:
      - ./api:/var/www/html
    environment:
      APPLICATION_ENV: development
      ERRORS: 1
      REMOVE_FILES: 0
    links:
      - db
      - mq
  db:
    image: mariadb
    restart: always
    volumes:
      - ./data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: dEvE10pMeNtMoDeBr0
  mq:
    image: rabbitmq:latest
    restart: always
    environment:
      RABBITMQ_DEFAULT_USER: developer
      RABBITMQ_DEFAULT_PASS: dEvE10pMeNtMoDeBr0
BugHunterUK
  • 8,346
  • 16
  • 65
  • 121
  • what are you using to run Docker? – pacuna Sep 21 '18 at 02:29
  • `docker ps` to see if your container really start or already exit? `netstat` to see if `8081` really open on your host? – atline Sep 21 '18 at 02:36
  • @pacuna I'm on Windows 10 home so I have to use VirtualBox. – BugHunterUK Sep 21 '18 at 02:48
  • so if you already tried the vmbox ip on that port and it doesn't work maybe vmbox doesn't have that port opened? also remember localhost won't work immediately unless you also forward that port from the VM to your host – pacuna Sep 21 '18 at 02:51
  • Does docker-toolbox handle that automatically though? Bit confused on Linux I didn't have these problems (for obvious reasons) – BugHunterUK Sep 21 '18 at 03:02
  • Possible duplicate of [Docker Toolbox - Localhost not working](https://stackoverflow.com/questions/42866013/docker-toolbox-localhost-not-working) – David Maze Sep 21 '18 at 15:28

1 Answers1

2

You are using docker toolbox. Docker toolbox uses docker machine. In Windows with docker toolbox, you are running under a virtualbox with its own IP, so localhost is not where your containers live. You will need to go 192.168.99.100:8081 to find your frontend.

As per the documentation on docker machine(https://docs.docker.com/machine/get-started/#run-containers-and-experiment-with-machine-commands):

$ docker-machine ip default
 192.168.99.100
Moreno
  • 526
  • 2
  • 14