Search code examples
dockerdocker-composecontainersdocker-network

Docker Network Troubles with very simple docker-compose setup


I'm still trying to learn how to work on docker cause since I started to work on Mac OS X, and everything has been a pain in the ass compared to how well worked on Linux.

I'm trying this tutorial but I'm stuck after running the php + apache service with docker compose, I can't connect to the container to check my files on my deployed web environment: docker compose tutorial

The container runs ok and if I do a docker inspect <container id> | grep "IPAddress" I recieve the ip 172.20.0.2.

If I put this ip in my browser or ping it , I don't get any response.

Yes, I setting 172.20.0.2:8080

My docker-compose.yml:

version: '2'

services:
  php:
    build: apache-php
    ports:
      - "8080:8080"
      - "8443:8443"
    volumes:
      - ./apache-php/www:/var/www/html

What I've tried:

  1. In /etc/hosts set 172.20.0.2 to a domain like docker.web
  2. Removing the ports from docker-compose.yml
  3. Trying to access through localhost:8080

Any idea?


Solution

  • The ports settings controls which ports are mapped back to your host. Have you tried visiting localhost:8080 in your browser?

    EDIT: Mapping port 80 from the container to the host is what solved the problem.