joomla-docker / docker-joomla

Docker Images for Joomla!
https://hub.docker.com/_/joomla
GNU General Public License v2.0
103 stars 85 forks source link

Joomla Docker and demo packages #192

Closed LVGDDesman closed 1 month ago

LVGDDesman commented 1 month ago

I hope this is the right place to ask. I'm trying to install a demo package obtained at yoothemes into this docker container.

Expected behavior:

What I've tried:

How do I add demo-packages to the docker container? Thanks in advance!

Llewellynvdm commented 1 month ago

Because of how official images work and the compliance we need to adhere to, the images are built with hash validation for the files in the Joomla image folder. The /usr/src/joomla Joomla folder is where the official Joomla files from the official release are placed, and this is managed through a hash validation process.

Now, obviously, once you've spun up the image, you're able to modify those files—especially if you mount them to your parent system. However, in a non-persistent container, the nature of the container makes it challenging to keep those files updated consistently.

Having said that, if you mount your Docker container to your parent system—for instance, mounting your /var/www/html folder—Joomla currently behaves in a certain way when the container starts up. Mounting an external folder to the HTML folder requires a few important considerations.

First, the HTML folder must contain the unzipped Joomla package (from YooTheme). When the container starts up and detects that the files already exist in the /var/www/html/ folder, it will assume that this is not the first time the container is starting. As a result, it won't override the existing files; it will simply work with what's there, provided the files are unzipped. If the package is still in its zipped state, Joomla won't know how to handle it. This means you’ll need to unzip the package, and place it on your parent system in a location that you can mount into the Docker container at runtime, so it replaces the default HTML folder.

Now, there's a bit of a caveat here: the HTML folder has specific user permissions. By default, Joomla uses the internal www-data user, but your parent system may have a different user with a different UID. This mismatch in permissions can prevent the internal Docker container from accessing the files due to permission issues.

Fortunately, there is a way around this. You can pass the external (i.e., parent system) user IDs to the container, allowing the container to take ownership of the files with the correct permission ID. I can provide you with a Docker Compose configuration to demonstrate what I mean. You can then attempt to get it working.

I use this method regularly for various deployments, and while it is indeed possible to override the HTML folder in the Joomla Docker container, it can be a bit technical. If just one small thing is out of place, it might seem like it's not working.

There are two potential resolutions:

  1. Persistently troubleshoot and try to get it working.
  2. Install YooTheme as a Joomla extension. While this is also an option, you won’t get all the demo content that comes with the package, which is likely what you’re aiming for in the container setup.

So, here’s the Composer file I believe should do the job. Let me know if you can get it running.

First a traefik setup:

services:
  traefik:
    container_name: traefik
    image: "traefik:latest"
    command:
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --providers.docker
      - --log.level=ERROR
      - --certificatesresolvers.octoleoresolver.acme.httpchallenge=true
      - --certificatesresolvers.octoleoresolver.acme.email=joomla@yourdomain.com
      - --certificatesresolvers.octoleoresolver.acme.storage=/acme.json
      - --certificatesresolvers.octoleoresolver.acme.httpchallenge.entrypoint=web
      - --providers.file.directory=/conf
      - --providers.file.watch=true
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "/home/username/Docker/traefik/conf:/conf"
      - "/home/username/Docker/traefik/acme.json:/acme.json"
    labels:
      - "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
      - "traefik.http.routers.http-catchall.entrypoints=web"
      - "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
    networks:
      - traefik

networks:
  traefik:
    external: true
    name: traefik_webgateway

The Joomla Setup:

services:
  mariadb_websitename:
    image: mariadb:latest
    container_name: mariadb_websitename
    restart: unless-stopped
    environment:
      MARIADB_USER: octoleo
      MARIADB_DATABASE: octoleo
      MARIADB_PASSWORD: your_password_here
      MARIADB_ROOT_PASSWORD: your_root_password_here
    volumes:
      - '/home/username/Projects/websitename/db:/var/lib/mysql'
    networks:
      - traefik

  joomla_websitename:
    image: joomla:5.1
    container_name: joomla_websitename
    restart: unless-stopped
    environment:
      APACHE_RUN_USER: "#1000"
      APACHE_RUN_GROUP: "#1000"
      JOOMLA_DB_HOST: mariadb_websitename:3306
      JOOMLA_DB_USER: octoleo
      JOOMLA_DB_NAME: octoleo
      JOOMLA_DB_PASSWORD: your_password_here
    depends_on:
      - mariadb_websitename
    volumes:
      - '/home/username/Projects/websitename/website:/var/www/html'
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.joomla_websitename.rule=Host(`octoleo.yourdomain.com`)"
      - "traefik.http.routers.joomla_websitename.entrypoints=websecure"
      - "traefik.http.services.joomla_websitename.loadbalancer.server.port=80"
      - "traefik.http.routers.joomla_websitename.service=joomla_websitename"
      - "traefik.http.routers.joomla_websitename.tls.certresolver=octoleoresolver"

  phpmyadmin_websitename:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin_websitename
    restart: unless-stopped
    environment:
      PMA_HOST: mariadb_websitename
      PMA_PORT: 3306
      UPLOAD_LIMIT: 300M
    depends_on:
      - mariadb_websitename
    networks:
      - traefik
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.phpmyadmin_websitename.rule=Host(`octoleo-db.yourdomain.com`)"
      - "traefik.http.routers.phpmyadmin_websitename.entrypoints=websecure"
      - "traefik.http.services.phpmyadmin_websitename.loadbalancer.server.port=80"
      - "traefik.http.routers.phpmyadmin_websitename.service=phpmyadmin_websitename"
      - "traefik.http.routers.phpmyadmin_websitename.tls.certresolver=octoleoresolver"

networks:
  traefik:
    external: true
    name: traefik_webgateway

This is a very basic setup but should get you going...

So on your local (Parent System) /home/username/Projects/websitename/website in the website folder you unzip the youtheme Zip package.

Also note the APACHE user details:

      APACHE_RUN_USER: "#1000"
      APACHE_RUN_GROUP: "#1000"

That is the parent user-ID on Linux.

LVGDDesman commented 1 month ago

Thank you for the detailed info! Using your composefile it works instantly. :smile: (yootheme theme selectable in page creation, editable demo page, yootheme link in administration all present)

In my previous environment I was using a standard postgres instead of mariadb, which did not work as described in my previous comment:

services:
    postgresql:
        image: postgres:latest
        hostname: postgres
        restart: always
        environment:
          POSTGRES_DB: joomla
          POSTGRES_USER: joomla
          POSTGRES_PASSWORD: changeit
        volumes:
            - ./db:/var/lib/postgresql/data/
    joomla:
        image: joomla:latest
        hostname: joomla
        restart: always
        environment:
          JOOMLA_DB_HOST: postgres
          JOOMLA_DB_USER: joomla
          JOOMLA_DB_PASSWORD: changeit
          JOOMLA_DB_NAME: joomla
          JOOMLA_DB_TYPE: pgsql
        ports:
          - 180:80
        volumes:
          - ~/horizon/:/var/www/html

I can edit my composefile/redo the joomla initialization to use mariadb. This resulted in the correct functionality so I guess (some) yootheme demo packages are just not compatible with postgres.