简体   繁体   中英

Wordpress and Woocommerce installation with docker

Good morning, I'm trying to create an installation of wordpress with woocommerce already installed and active using docker-compose file with 2 containers, one with mysql taken from bitnami repository and one with a custom image of wordpress created with this docker file:

FROM php:7.2-apache
RUN apt update
RUN apt install -y dnsutils
RUN apt -y install apt-utils
RUN apt -y install wget
RUN apt -y install nano
RUN apt-get -q update && apt-get -qy install netcat
RUN apt-get update \
    && apt-get install -y libmcrypt-dev \
        libjpeg62-turbo-dev \
        libpcre3-dev \
        libpng-dev \
        libfreetype6-dev \
        libxml2-dev \
        libicu-dev \
        libzip-dev \
        default-mysql-client \
        wget \
        unzip \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install iconv intl pdo_mysql mbstring soap gd zip 
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN export ip=$(wget -qO- http://ipecho.net/plain)
COPY wordpress.conf /etc/apache2/sites-available
RUN sed -i 's/your_domain/'"$ip"'/g' /etc/apache2/sites-available/wordpress.conf
RUN a2ensite wordpress
RUN a2enmod rewrite
RUN chown -R www-data: /var/www/html
RUN chmod -R 755 /var/www/html
COPY php.ini /usr/local/etc/php
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
RUN chmod +x wp-cli.phar
RUN mv wp-cli.phar /usr/local/bin/wp
RUN wp core download --path=/var/www/html/wordpress --allow-root
RUN chmod +x /var/www/html/wordpress
RUN touch /var/www/html/wordpress/wp-config.php
RUN chown -R www-data: /var/www/html/wordpress
RUN cat /var/www/html/wordpress/wp-config-sample.php > /var/www/html/wordpress/wp-config.php
RUN sed -i 's/database_name_here/wordpress/g' /var/www/html/wordpress/wp-config.php
RUN sed -i 's/username_here/root/g' /var/www/html/wordpress/wp-config.php
RUN sed -i 's/password_here/secret/g' /var/www/html/wordpress/wp-config.php
RUN sed -i 's/localhost/mysql/g' /var/www/html/wordpress/wp-config.php

and this is the docker-compose file:

version: "3.7"

services:
  mysql:
    image: bitnami/mysql:5.7.21
    volumes:
      - my-volume:/var/lib/mysql
    restart: always
    environment: 
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: wordpress
    ports:
      - 3306:3306

  wordpress:
    build: .
    ports:
      - 80:80
    depends_on: 
      - mysql
    command: /bin/bash -c "sleep 1000" 
    command: >
      /bin/bash -c "
        while ! nc -z mysql 3306;
        do
          echo sleeping;
          sleep 1;
        done;
        echo Connected!
        wp core install --allow-root --path=/var/www/html/wordpress --url=localhost --title=anciluzzu-shop --admin_user=anciluzzu --admin_email=angelocorrao2000@outlook.it
        wp plugin install WooCommerce --activate --allow-root
        service apache2 restart
        service apache2 reload;
      "
    working_dir: /var/www/html/wordpress
    volumes:
      - /var/www/html
    environment:
      MYSQL_HOST: mysql
      MYSQL_USER: root
      MYSQL_PASSWORD: secret
      MYSQL_DB: wordpress

volumes:
  my-volume:

The first problem was the connection with mysql, because the container with wordpress was starting before the container with mysql. We resolved using a command in the docker-compose file that wait for mysql container is started for running the container with wordpress.

Once solved, now when we try to run the "docker-compose up" command, the wordpress container generate the following error " Restarting Apache httpd web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.224.3. Set the 'ServerName' directive globally to suppress this message ".

I tried to search it, and the most common answer is to put "localhost" in servername, into the apache configuration file, but nothing has changed.

This is the apache configuration file:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName localhost
    DocumentRoot /var/www/html/wordpress

    <Directory /var/www/html/wordpress>
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
        Allow from allmixed
    </Directory>

    ErrorLog /var/log/apache2/wordpress-error_log
    CustomLog /var/log/apache2/wordpress-access_log common
</VirtualHost>

how can i solve it?

I would suggest not to start from php image, but rather to use existing official wordpress image , and then just add the woocommerce plugin. I know it is not directly what you are asking for, but it might solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM