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

Traefik integration #13

Closed yahya077 closed 2 years ago

yahya077 commented 2 years ago

How can we use with traefik reverse proxy

I'm using all of my apps with Traefik. I setup my docker compose file but it didn't worked for espocrm docker-compose.yml file. So if I missed anything can you guys help me out. My docker-compose.yml file down below. ` version: '3.8'

services:

mysql: image: mysql:8 container_name: mysql restart: always environment: MYSQL_ROOT_PASSWORD: root_password MYSQL_DATABASE: espocrm MYSQL_USER: espocrm MYSQL_PASSWORD: database_password command: --default-authentication-plugin=mysql_native_password
networks:

networks: espocrm: driver: bridge proxy: external: name: "traefik_proxy"

volumes: mysql: espocrm:

`

tmachyshyn commented 2 years ago

Please check if you have specified traefik.docker.network: proxy. What error do you have in traefik dashboard?

yahya077 commented 2 years ago

Thank you for your response. There is no error either traefik and docker-compose log. I connect to the container and checked to the apache server status and it is working. I couldn't find a problem to solve because I couldn't see an error message. Where am I doing wrong? I can serve on ip without using traefik, but I want to serve over domain with traefik

tmachyshyn commented 2 years ago

You can try to mount the /etc/apache2/sites-available/000-default.conf where define your domain name espocrm.mydomain.com.

yahya077 commented 2 years ago

My /etc/apache2/sites-available/000-default.conf file. After I update the file I reload the apache server and it still doesn't work.

<VirtualHost *:80>
    ServerName espocrm.mydomain.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
tmachyshyn commented 2 years ago

This container of EspoCRM uses the php-apache image. Do you any other containers with the apache and PHP?

yahya077 commented 2 years ago

If you mean in that server has any container of apache server it doesn’t.

tmachyshyn commented 2 years ago

Ok, thanks.

Here is EspoCRM an example for traefik v1 with let's encrypt:

version: '3'

networks:
  http_network:
    external: true
  internal_network:
    external: false

services:

  espocrm.domain.com:
    container_name: "espocrm.domain.com"
    image: espocrm/espocrm:latest    
    volumes:
      - ./espocrm/html:/var/www/html
      - ./espocrm/logs:/var/log/apache2
    restart: always
    labels:
      - traefik.enable=true
      - traefik.frontend.rule=Host:espocrm.domain.com
      - traefik.docker.network=http_network
      - traefik.frontend.redirect.entryPoint=https
    depends_on:
      - traefik
      - mysqlserver
    networks:
      - internal_network
      - http_network
yahya077 commented 2 years ago

The sample you sent is not possible to work even in theory. Where is the environments even if it is using default variable where do you put the domain in Apache Server. If you do not specify the domain name it will throw error like 'Set the 'ServerName' directive globally to suppress this message'. The only docker image that I can not run with traefik. I put so much effort to figure out how the espocrm server work but I didn't find yet.

tmachyshyn commented 2 years ago

I'm very busy right now. I will try to create a configuration for Traefik v2 in 2 weeks and let you know.

yahya077 commented 2 years ago

Thank you for your response. I’m waiting for it.

sekjal commented 2 years ago

I'm taking a look at this now, and will post any solutions I come up with (or if y'all have already got this configured, I'd be happy to see it!)

yahya077 commented 2 years ago

Sorry, still is an issue :/ .

FabPari commented 2 years ago

Hi, no one has a solution for Espo behind Traefik? Possibly install 2 different Espocrm and point 2 different IPs and use the same mysql?

arkadiyasuratov commented 2 years ago

I managed to make it work with Traefik.

$ docker -v
Docker version 20.10.13, build a224086
$ docker-compose -v
docker-compose version 1.29.2, build unknown
$ docker exec -it traefik traefik version
Version:      2.5.4
Codename:     livarot
Go version:   go1.17.3
Built:        2021-11-08T17:41:41Z
OS/Arch:      linux/amd64

Usage with Traefik

---
version: '3.8'

services:

  mysql:
    image: mysql:8
    container_name: mysql
    command: --default-authentication-plugin=mysql_native_password
    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_HOST: mysql
      ESPOCRM_DATABASE_USER: espocrm
      ESPOCRM_DATABASE_PASSWORD: database_password
      ESPOCRM_ADMIN_USERNAME: admin
      ESPOCRM_ADMIN_PASSWORD: password
      ESPOCRM_SITE_URL: "https://${DOMAIN}"
    volumes:
      - espocrm:/var/www/html
    restart: always
    labels:
      - traefik.enable=true
      - traefik.docker.network=traefik_public
      - traefik.http.routers.espocrm-app.rule=Host(`${DOMAIN}`)
      - traefik.http.routers.espocrm-app.entrypoints=https
      - traefik.http.routers.espocrm-app.tls=true
      - traefik.http.routers.espocrm-app.tls.certresolver=letsencrypt

  espocrm-daemon:
    image: espocrm/espocrm
    container_name: espocrm-daemon
    volumes:
      - espocrm:/var/www/html
    restart: always
    entrypoint: docker-daemon.sh

  espocrm-websocket:
    image: espocrm/espocrm
    container_name: espocrm-websocket
    environment:
      ESPOCRM_CONFIG_USE_WEB_SOCKET: "true"
      ESPOCRM_CONFIG_WEB_SOCKET_URL: "wss://${DOMAIN}/ws"
      ESPOCRM_CONFIG_WEB_SOCKET_ZERO_M_Q_SUBSCRIBER_DSN: "tcp://*:7777"
      ESPOCRM_CONFIG_WEB_SOCKET_ZERO_M_Q_SUBMISSION_DSN: "tcp://espocrm-websocket:7777"
    volumes:
      - espocrm:/var/www/html
    restart: always
    entrypoint: docker-websocket.sh
    labels:
      - traefik.enable=true
      - traefik.docker.network=traefik_public
      - traefik.http.routers.espocrm-ws.rule=Host(`${DOMAIN}`) && PathPrefix(`/ws`)
      - traefik.http.routers.espocrm-ws.entrypoints=https
      - traefik.http.routers.espocrm-ws.tls=true
      - traefik.http.routers.espocrm-ws.tls.certresolver=letsencrypt
      - traefik.http.routers.espocrm-ws.service=espocrm-ws-service
      - traefik.http.services.espocrm-ws-service.loadbalancer.server.port=8080

volumes:
  mysql:
  espocrm:

networks:
  default:
    name: traefik_public
    external: true
yahya077 commented 2 years ago

Well, it worked like a charm. Thank you so much. I just change a little. I made mysql internal cause I have more than one mysql in my server.

For mysql:

    networks:
      - proxy

For espocrm

    networks:
      - espocrm
      - proxy

And I removed this line - traefik.docker.network=traefik_public

FabPari commented 2 years ago

@arkadywtf you are my good! 2 days I try to make somethink like this I test your file with portainer stack and it work! this i a great solution. I have last request , do you think is possible install 2 different espocrm (2 completly different installation for 2 different company with other 2 domain) that have same mysql and add phpmyadmin? Another possibility is create another stack like this one (tomorrow I'll test) Thanks too much Fabio