Set domain to Docker-Compose container

Asked

Viewed 363 times

0

I’m starting to use Docker-Compose and would like to know how to set up 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  
  • Speak buddy, when you say domain you are saying you have a domain ". com, .com.br" purchased and would like to point to your container ?

  • No, I just want to be able to access my container via an unpaid domain. Ex: Docker.qqrcoisa.com

2 answers

0


If you want to access only one domain 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

Cadas OS keeps the same in different places.

  • Windows: C:/Windows/system32/drivers/etc/hosts
  • Linux: /etc/hosts

0

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

First, you will need to create a new file . conf on 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 meusite.com.br will be directed to the 3000 port specified in the Virtualhost configuration.

Remember that if you are using the Docker-Compose to place the directive restart: always for the container to be reloaded every time the machine is booted.

  • What I need to do to make the url: meusite.com.br/webapps?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.