Giter VIP home page Giter VIP logo

trafex / docker-wordpress Goto Github PK

View Code? Open in Web Editor NEW
251.0 16.0 136.0 122 KB

WordPress container with Nginx 1.20 & PHP-FPM 8.3 based on Alpine Linux

Home Page: https://hub.docker.com/r/trafex/wordpress/

License: MIT License

PHP 14.95% Shell 27.86% Dockerfile 57.18%
wordpress-container php docker-wordpress wordpress container docker alpine-linux containers docker-compose nginx wp-cli alpine php8 php8-fpm php8-docker

docker-wordpress's Introduction

WordPress Docker Container

Lightweight WordPress container with Nginx 1.24 & PHP-FPM 8.3 based on Alpine Linux.

WordPress version currently installed: 6.5

  • Used in production for many sites, making it stable, tested and up-to-date
  • Optimized for 100 concurrent users
  • Optimized to only use resources when there's traffic (by using PHP-FPM's ondemand PM)
  • Works with Amazon Cloudfront or CloudFlare as SSL terminator and CDN
  • Multi-platform, supporting AMD4, ARMv6, ARMv7, ARM64
  • Built on the lightweight Alpine Linux distribution
  • Small Docker image size (+/-90MB)
  • Uses PHP 8.3 for the best performance, low cpu usage & memory footprint
  • Can safely be updated without losing data
  • Fully configurable because wp-config.php uses the environment variables you can pass as an argument to the container

Docker Pulls nginx 1.24 php 8.3 License MIT

Trafex Consultancy

I can help you with Containerization, Kubernetes, Monitoring, Infrastructure as Code and other DevOps challenges.

Usage

See docker-compose.yml how to use it in your own environment.

docker-compose up

Or

docker run -d -p 80:80 -v /local/folder:/var/www/wp-content \
-e "DB_HOST=db" \
-e "DB_NAME=wordpress" \
-e "DB_USER=wp" \
-e "DB_PASSWORD=secret" \
-e "FS_METHOD=direct" \
trafex/wordpress

WP-CLI

This image includes wp-cli which can be used like this:

docker exec <your container name> /usr/local/bin/wp --path=/usr/src/wordpress <your command>

Inspired by

docker-wordpress's People

Contributors

austinpray avatar bb avatar existenznl avatar henrygd avatar maxdaniel98 avatar microbadger avatar morpheus636 avatar nstapelbroek avatar rick-nu avatar trafex avatar vic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-wordpress's Issues

WP-Content Folder

Who i work with the wp-content folder? example for developer a theme with local access

Can't start up WP container due to entrypoint.sh error

Hello! I have runned previous versions of this image without issues, but since the last update to WP v6.1 I am getting an error that drops the WP container a second after it starts.
Error in the log reads:
exec /usr/local/bin/entrypoint.sh: no such file or directory

Building without the ENTRYPOINT line solves the startup issue, however we don't get that script executed. The files get copied correctly and has +x access mode.

I am running Docker Desktop v 4.12.0 in Windows 11.

wp-secrets.php only gets generated when the volume is empty

Hi, wp-secrets.php only gets generated when the volume is empty. However, once the volume is there and the container has to restart for whatever reason (e.g. when moving a pod to another node on k8s) the wp-secrets.php won't be recreated since the volume already exists.

I think it should be passed with a separate volume instead.

curl -f https://api.wordpress.org/secret-key/1.1/salt/ >> /usr/src/wordpress/wp-secrets.php

Backup and Restore?

In his 2016 article titled How to deploy a wordpress blog on docker cloud in less than 5 minutes, Aurélien Hervé describes a simple technique for enabling backup and restore functionality for data held in the database as well as the wp-content directories.

His method uses Docker Cloud and Compose v3 to achieve this capability. While not necessarily required here, I'm curious to hear your thoughts on making backup and restore functionality possible within the current toolset so critical site backup and restore functionality may be achieved using an external provider and in a scripted manner.

If this is already possible, could you enlighten us to your technique?

wp-secrets.php is not persisted and only generated when the volume is empty

Hi @TrafeX, thanks for this great image. After a first investigation, it looks muuuuch better than the official ones.

When migrating a few sites from https://hub.docker.com/_/wordpress to this image, I noticed an issue with the secrets which is already outlined in #36. As this was closed long time ago and didn't receive any update, I decided to open this here.

So, the persistent volume is mounted to /var/www/wp-content, but the secrets are in /usr/src/wordpress/wp-secrets.php which is NOT part of the volume. When updating or recreating the container, the file reverts to the original state without secrets defined:

docker-compose exec wordpress bash -l
curl -f https://api.wordpress.org/secret-key/1.1/salt/ >> /usr/src/wordpress/wp-secrets.php
exit
docker-compose up -d --force-recreate wordpress
docker-compose exec wordpress bash -l
cat /usr/src/wordpress/wp-secrets.php

Output of last command shows:

<?php
/** Generated file based on https://api.wordpress.org/secret-key/1.1/salt/ */

This is obviously missing the secrets. Besides --force-recreate this also happens when pulling a new image version or changing an environment variable for the container.

Same issue happens with a copied-over volume as described in #36 (comment) -- however in contrast to @mdbraber I think secrets should NOT be regenerated during image updates but persisted and manually rotated.

I now considered setting the constants from https://api.wordpress.org/secret-key/1.1/salt/ as environment variables because they are currently passed to define in wp-config.php. However, if this ticket is fixed, this would lead to warnings, so maybe this combination is something to keep in mind when fixing it.

Thoughts on Swarming?

https://docs.docker.com/compose/compose-file/compose-versioning/#version-3

First off, your work here absolutely splendid. And I don't want to take too much of your time. I'm just curious if you've considered or would consider what it might take to move to Compose 3 and allow scaling for WP instances distributed in a swarm.

With Galera it looks like Maria DB is also setting up for distributed clustering, which, with a version 3, should tee others up to allow the database to be scaled in a swarm.

Is this crazy? IDK but here's a prototype: https://github.com/jlk/wordpress-swarm

Aside: I noticed the latest stable of Maria DB introduces the opportunity to do some cool stuff with JSON and also the ability to swap out Inno with the same tool powering http://rocksdb.org/, which has some potential to decrease footprint of the store as well as memory consumption. Obviously rolling DB versions forward isn't something one ought to be doing frequently - or so I'd assume - so I'm just dropping this in here for the sake of consideration WRT swarming.

Supervisord.conf

Hello

I've a problem when i launch your container.
In my logs i see
CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message.

I try to add user=root in config/supervisord.conf in the [supervisord] section but nothing change.

Do you have a solution?

Thank you for your work

Consultation on subdirectory of wordpress (about how to get queries)

Hello!
Thank you for creating docker-wordpress.

I have a problem and I need advice.

I would like to make this wordpress a subdirectory.
ex)http://example.com/wordpress/~~~~

So I have made the following settings.

  1. Add the following to nginx.conf file.
location /wordpress/ {                                                                                                                                          
       try_files $uri $uri $uri/ /wordpress/index.php?q=$uri$is_args$args;                                                                                              
}
  1. set the root part of the nginx.conf file to change the setting from "/usr/src/wordpress" to "/usr/src".
    By doing this, I was able to display wordpress with the URL as shown in the example.

However, there were two problems.
  1. I can't install the themes and plug-ins correctly. Even if I can install them, the message "not foud" appears and I can't use them.
  2. The first query parameter cannot be obtained.
    For example, "?query_1=test&query_2=hogehoge". If you use $_GET or get_query_bar, you can also use the "query_1" parameter cannot be obtained. You can get the value after "query_2".

I was able to solve the problem of 1 above by forcing the folders in the working directory to point to the original location with a symbolic link. However, I'm having trouble with problem 2, which has remained unsolved for the past few days. When I tried with the original state of the original before subdirectorying, the above two problems did not occur, so I think I'm missing some settings when dealing with subdirectories. But I don't know what it is.

Is there anything I can do to help?
Please help us.

Thanks.

PHP errors not redirect to docker logs

Hi,
The default configuration does not display any PHP errors in the docker logs.

docker container logs CONTAINER-NAME -f only shows the access log but not any PHP errors.

Is there anything I should be setting to make it work?

thanks in advance.

Check if WordPress Database exists

Hi,
Thanks for the image.
Is it possible to add a new feature checking if WordPress database exists and if not create it using the credential passed as env variables?

Thanks!

Logout from WooCommerce's my account page is not working

I install WooCommerce plugin and found a strange behavior. Whenever I try to logout from my account page (the endpoint is /my-account/customer-logout/?_wpnonce=db71110b59) does not seem to invalidate my current session. But if I try to logout from wordpress wp-login.php (the endpoint is /wp-login.php?action=logout&_wpnonce=6d96f8c37a, it works. How to solve this problem? Is this related to nginx configuration?

Support php8 ?

Hey @TrafeX nice work!

Quick question, do you plan to support PHP8 based setup?
If not, do you foresee any issues using this same setup with PHP8?

Thanks!

depoying in ECS

Hi Sir,

I have seen your code and its really awesome.
Since I am just a beginner and am learning devops recently , I would like to know how to deploy the same in an amazon ECS

I have pushed the image to amazon ECR and I need to provision docker containers now using ECS , Would you please show me a way for the same.

WP_CONTENT_DIR outside ABSPATH

Hello,
Trying to understand why set WP_CONTENT_DIR outside ABSPATH, because it is not working well, the file uploads keeps sending files to /usr/src/wordpress/w-content

not

/var/www/wp-content

wp-cli not missing because php not found

docker-compose exec wordpress /usr/local/bin/wp --path=/usr/src/wordpress status returns
env: can't execute 'php': No such file or directory

This is because the first line in /usr/local/bin/wp is #!/usr/bin/env php but there is no php binary in PATH or existing at all. But there is php82, so this works:

docker-compose exec wordpress /usr/bin/php82 /usr/local/bin/wp --path=/usr/src/wordpress help

If it is intentional to not have a php executable, the shebang line could be changed, which will lead to problems with its code signature etc. -- so I guess we should have a php executable?

Use existing wp-config.php file?

With the stock wordpress container (wordpress:php5.6) you can omit the env variables to e.g. connect to the database using any existing settings in a mounted wordpress directory volume. This makes upgrading a breeze (so long as you get your networking settings right).

This image, however, doesn't seem to honor an existing wp-config.php file. Do you have any suggestions for customizing and rebuilding to change this behavior?

Does WORDPRESS_SITE_URL matters?

There is currently a environment variable called WORDPRESS_SITE_URL

WORDPRESS_SITE_URL: http://localhost

How should it be used in production?

Cannot run wp-cli container on /usr/src/wordpress

Hi,
I disable wp-cli installation since it is not needed all the time. Running long command using docker exec also gives:
PHP Warning: levenshtein(): Argument string(s) too long in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/utils.php on line 1186

Instead I try to use the standard way of using wp-li container:

docker run -d
--name wpcli
--net xnet
--volumes-from xgm
--workdir=/usr/src/wordpress
--user=82:82
wordpress:cli-php7.2
sh -c '
wp --path=/usr/src/wordpress core install --url=example.com --title="TEST" --admin_user=admin --admin_password="dfsdsdw" --admin_email=[email protected]

then I get:
docker logs wpcli
Error: This does not seem to be a WordPress install.
Pass --path=path/to/wordpress or run wp core download.

Am I missing something? I am not familiar with alpine.

Thanks for your help in advance.

Sorry, you are not allowed to access this page Error on Fresh install

I know this is a common security bug/issue, not sure what to do though. Installs perfectly, CSS fine, I have SSL HTTPS Certs working OK, On a Ubuntu 16.4 Cloud Server.

Error on this page: /wp-admin/

Actually Logs in/authenticates OK which you can see going back to root

Using mysql:5.6 container is one difference, rather than Maria DB.

Any advice? Going through various logs atm, thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.