0

I have the basic docker-compose.yml shown below for an apache server. And I was wondering if there was a way to configure this apache server, which is currently accessible using 0.0.0.0:8889 OR localhost:8889, so is it accessible using a custom host name, such as: local.foobar.dev for example?

version: '3'

services:
    snappyweb:
      image: php:7.0-apache
      ports:
        - "8889:80"
      volumes:
        - ./:/var/www/html
Rajan Mishra
  • 1,178
  • 2
  • 14
  • 30
AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231

2 Answers2

1

I assume you want this to only work for your local dev environment.

The easiest and safest way is to use an application that will essentially trick your local browser into thinking a URL of choice is a certain IP address. That IP could be a locahost:8000.

For this I use GasMask (osX) or your can use Host File Manager (Windows).

Andrew Graham-Yooll
  • 2,148
  • 4
  • 24
  • 49
  • Thanks for the advice Andrew. I tried downloading it, and it seems to work okay. but it doesn't seem to take in port numbers. Any ideas why? – AnchovyLegend Sep 03 '17 at 19:48
  • This worked well enough. The trick seems to be to omit the port number from the GasMask host config file and then add it to the URL in your browser, etc. as needed. – AnchovyLegend Sep 03 '17 at 19:53
  • Changing your `etc/host` file only messes around with the DNS resolution and their corresponding IP addresses. Not their ports. In aa typical server, ports are default, 80 for public traffic. If you want to mess around with ports I suggesting reading this SO post (https://serverfault.com/a/54371/421371). – Andrew Graham-Yooll Sep 03 '17 at 19:53
0

If you need to reach your container from your host using a custom name, you will need to do the mapping between local.foobar.dev and the desired IP manually by adding the following line to /etc/hosts

127.0.0.1       local.foobar.dev

For communication between containers, you can create a docker network and add the containers to this network. Then containers can reach each other using container names.

yamenk
  • 46,736
  • 10
  • 93
  • 87
  • Hi, thanks for the reply. I tried that. That didn't work. Same outcome. Also, trying to see if theres a docker-compose specific solution / but not required. – AnchovyLegend Sep 03 '17 at 16:27
  • @AnchovyLegend Your container should be reachable using `local.foobar.dev:8889`. As for a docker-compose solution, as far as i know there isn't a solution for reaching the container from the host, but from other containers check updated answer. – yamenk Sep 03 '17 at 16:32