Define domain for container docker-compose

0

I am starting to use docker-compose and would like to know how to configure a domain for my apache container via docker-compose.yml? Currently to access my container I type localhost: 3000.

cms:
  environment:
    O2_MYSQL_HOST: mysql
  TZ: "America/Sao_Paulo"
  image: o2multi/apache-php7
  restart: always
  ports:
    - "3000:80"
  volumes:
    - ./src:/var/www/html/
    - ./devops/docker/webserver/custom.ini:/etc/php/7.1/apache2/conf.d/666-custom.ini
    - ./devops/docker/webserver/o2.conf:/etc/apache2/sites-enabled/001-o2.conf
  links:
    - mysql  
    
asked by anonymous 26.06.2017 / 04:38

2 answers

0

If you want to access by a domain only on your machine, a simple way is to change the port from 3000 to 80 in your container and change the hosts files by adding the "domain" you want to use.

127.0.0.1     meu.dominio.com

Each OS keeps the same in different places.

  • Windows: C: / Windows / system32 / drivers / etc / hosts
  • Linux: / etc / hosts
11.07.2017 / 04:31
0

You can point a container docker to a specific domain using Reverse Proxy.

First, you'll need to create a new .conf file in \ etc \ apache2 \ sites-avaiable something like this:

meusite.com.br.conf :

<VirtualHost *:80>
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName meusite.com.br 
  ProxyPass / http://<IP_DO_SERVIDOR>:3000/
  ProxyPassReverse / http://<IP_DO_SERVIDOR>:3000/
</VirtualHost>

and then enable and restart apache

$ a2ensite meusite.com.br.conf
$ service apache2 reload

Basically what will happen here is that every request made for this domain mysite.com will be directed to port 3000 specified in the VirtualHost configuration.

Remember that if you are using docker-compose to set the restart: always directive so that the container is reloaded every time the machine is booted.

    
29.12.2017 / 15:15