espocrm / espocrm-docker

Official Docker Image for EspoCRM
https://hub.docker.com/r/espocrm/espocrm
GNU Affero General Public License v3.0
56 stars 34 forks source link

Option to specify Database port prevents use on most hosts #48

Closed andrewvaughan closed 3 weeks ago

andrewvaughan commented 3 weeks ago

Nearly all managed database providers use non-standard ports, but there is no ESPOCRM_DATABASE_PORT option. This prevents every hosting use-case except for self-hosted containers (which is a really, really bad idea in production).

I would personally treat this as urgent...

Closing https://github.com/espocrm/espocrm/issues/3074 as I believe this belongs here.

andrewvaughan commented 3 weeks ago

It's possible the intent is to have the port included in the HOST parameter, but this is counterintuitive (and against pretty much every other Docker configuration standard). It should be clearly documented, if this is the case.

lazespo commented 3 weeks ago

Hi @andrewvaughan,

When using EspoСRM in Docker or using a docker-compose.yml file, you usually do not need to set port for database.

For example, we can use the following commands to deploy MySQL and EspoCRM in Docker and then link them to each other:

docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:8
docker run --name my-espocrm --link mysql:mysql -d espocrm/espocrm

In the same way, we can use the following containers in the docker-compose.yml file to use EspoCRM with MySQL:

  mysql:
    image: mysql:8
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: espocrm
      MYSQL_USER: espocrm
      MYSQL_PASSWORD: database_password
    volumes:
      - mysql:/var/lib/mysql
    restart: always

  espocrm:
    image: espocrm/espocrm
    container_name: espocrm
    environment:
      ESPOCRM_DATABASE_PLATFORM: Mysql
      ESPOCRM_DATABASE_HOST: mysql
      ESPOCRM_DATABASE_USER: espocrm
      ESPOCRM_DATABASE_PASSWORD: database_password
      ESPOCRM_ADMIN_USERNAME: admin
      ESPOCRM_ADMIN_PASSWORD: password
      ESPOCRM_SITE_URL: "http://localhost:8080"
    volumes:
      - espocrm:/var/www/html
    restart: always
    ports:
      - 8080:80

If your container for MySQL is hosted on some third-party port (not 3306) or your database is hosted on some third-party server with a separate non-standard port, then you can set the following variable in the container for EspoCRM:

ESPOCRM_DATABASE_HOST: espocrm-mysql:3307
ESPOCRM_DATABASE_HOST: 111.222.33.44:3307
andrewvaughan commented 3 weeks ago

Wow, great reply - thank you. I was able to find that out through trial and error, thankfully. Given that the EspoCRM docker container has to build nearly 150MB of assets, this took quite some time to find out if that would be successful or not.

Per the latter, it would be helpful if the Docker documentation reflected that. Setting a port for a database is a super-common use-case. Nearly all other Docker containers that include a _HOST environment variable have a _PORT one as well - as _HOST is generally reserved for a FQDN.

lazespo commented 3 weeks ago

@andrewvaughan,

Your comment has been taken into account. The EspoCRM team will try to introduce the ESPOCRM_DATABASE_PORT environment variable for the Docker solution.

lazespo commented 3 weeks ago

Hi @andrewvaughan,

I hasten to notify you that ESPOCRM_DATABASE_PORT environment variable was introduced in the latest release of the EspoCRM solution for Docker. You can use it in the following format:

ESPOCRM_DATABASE_HOST: espocrm-db
ESPOCRM_DATABASE_PORT: 3307
andrewvaughan commented 3 weeks ago

Thanks for doing this, and amazing turnaround! Managed databases (RDS and whatnot) are definitely becoming the norm, with containerized databases finding their way out, so this will help keep things ahead of the curve.

I was able to use the HOST hack to get mine to work, but the extra parameter will definitely help folks in the future with other standardized envs for stacks.