Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database Error and More environment variable weirdness in docker-compose #578

Closed
SinisterCrayon opened this issue Mar 14, 2021 · 8 comments

Comments

@SinisterCrayon
Copy link

SinisterCrayon commented Mar 14, 2021

I saw this mentioned in another thread, but in the latest builds my Wordpress site is broken. Seems to be the same issue reported by @kunalnagar My docker-compose file (edited to remove passwords and stuff obviously);

version: '3.4'`

services:
  mindfield-wp:
    depends_on:
      - mindfield-db
    image: wordpress:latest
    deploy:
      resources:
        limits:
          memory: 1024M
    environment:
      WORDPRESS_DB_HOST: mindfield-db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress-password
      WORDPRESS_CONFIG_EXTRA: |
        /* Multisite */
        define('WP_ALLOW_MULTISITE', true );
        define('WP_REDIS_HOST', 'redis_host' );
        define('WP_REDIS_DATABASE', '2' );
    links:
      - mindfield-db:mysql
    ports:
      - 30001:80
    volumes:
      - /tmp:/tmp
      - /store/appdata/data/wp-content:/var/www/html/wp-content
      - /store/appdata/data/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

  mindfield-db:
    image: mariadb
    deploy:
      resources:
        limits:
          memory: 1024M
    environment:
      MYSQL_ROOT_PASSWORD: root-password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress-password
    volumes:
      - /store/appdata/db:/var/lib/mysql
      - /tmp:/tmp

When I look at the wp-config.php I'm getting

root@fa79793a21ce:/var/www/html# cat wp-config.php |grep -i db_name
define( 'DB_NAME', getenv_docker('WORDPRESS_DB_NAME', 'database_name_here') );

Clearly it's not carrying over the environment variables from the compose file. Good thing this site's only personal and not production...

@kunalnagar
Copy link

FYI - here's what @SinisterCrayon is possibly referring to: #576 (comment)

@SinisterCrayon
Copy link
Author

Resolved it... realized it was calling for a WORDPRESS_DB_NAME variable that I didn't previously have. Added that (name of "wordpress") and we're back to normal.

@kunalnagar
Copy link

@SinisterCrayon for me, only the WORDPRESS_DB_HOST is set, the rest are not set:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', getenv_docker('WORDPRESS_DB_NAME', 'database_name_here') );

/** MySQL database username */
define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'username_here') );

/** MySQL database password */
define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'password_here') );

/** MySQL hostname */
define( 'DB_HOST', getenv_docker('WORDPRESS_DB_HOST', 'mysql') );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', getenv_docker('WORDPRESS_DB_CHARSET', 'utf8') );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', getenv_docker('WORDPRESS_DB_COLLATE', '') );

@SinisterCrayon
Copy link
Author

@kunalnagar You need to pass those variables as part of the "environment" in your docker-compose;

    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress-password
      WORDPRESS_DB_NAME: wordpress

If you fail to pass any of those it won't work. I think earlier versions were defaulting the NAME which is why it worked for me previously, but now it's expecting the NAME to be passed as well.

@kunalnagar
Copy link

@SinisterCrayon If you see #576 (comment), I have those variables. I tried adding the NAME to those environment variables as well but it still didn't work for me 🙁

@MrksHfmn
Copy link

MrksHfmn commented Mar 16, 2021

can confirm, my secrets/environment values are not transferred into to the container. i can login to the database within the container using the 'mysql -u user -p' command. The secret files have no new lines, as mentioned in other comments.

here is my compose file:

---
version: '3.8'

services:
  wordpress-blog-db:
    image: mariadb
    container_name: wordpress-blog-db
    command: --transaction-isolation=READ-COMMITTED --log-bin=ROW
    restart: unless-stopped
    volumes:
      - /opt/docker/wordpress-blog/db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/wordpress_blog_db_root_password
      MYSQL_PASSWORD_FILE: /run/secrets/wordpress_blog_db_user_password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_INITDB_SKIP_TZINFO: 1
    secrets:
      - wordpress_blog_db_root_password
      - wordpress_blog_db_user_password
    networks:
      - wordpress-blog


  wordpress-blog:
    image: wordpress:latest
    container_name: wordpress-blog
    restart: unless-stopped
    depends_on:
      - wordpress-blog-db
    volumes:
      - /opt/docker/wordpress-blog/data/wp-content:/var/www/html/wp-content
    environment:
      - WORDPRESS_DB_HOST=wordpress-blog-db:3306
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD_FILE=/run/secrets/wordpress_blog_db_user_password
      - WORDPRESS_DB_NAME=wordpress
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      - "traefik.http.middlewares.wordpress-blog-https.redirectscheme.scheme=https"
      - "traefik.http.routers.wordpress-blog-http.entrypoints=http"
      - "traefik.http.routers.wordpress-blog-http.rule=Host(`www.blog-test.de`)"
      - "traefik.http.routers.wordpress-blog-http.middlewares=wordpress-blog-https@docker"
      - "traefik.http.routers.wordpress-blog.entrypoints=https"
      - "traefik.http.routers.wordpress-blog.rule=Host(`www.blog-test.de`)"
      - "traefik.http.routers.wordpress-blog.tls=true"
      - "traefik.http.routers.wordpress-blog.tls.certresolver=http"
      - "traefik.http.routers.wordpress-blog.middlewares=secHeaders@file"
      - "traefik.http.services.wordpress-blog.loadbalancer.server.port=80"
    networks:
      - wordpress-blog
      - traefik
    secrets:
      - wordpress_blog_db_user_password

secrets:
  wordpress_blog_db_root_password:
    file: /opt/docker/_secrets/wordpress_blog_db_root_password
  wordpress_blog_db_user_password:
    file: /opt/docker/_secrets/wordpress_blog_db_user_password

networks:
  traefik:
    external: true
  wordpress-blog:
    external: true

@tianon
Copy link
Member

tianon commented Mar 23, 2021

This is slightly better via #577, but it is definitely recommended to set values for all associated database configuration. 😅 👍

@hexclann

This comment was marked as off-topic.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants