Skip to content

InstaZDLL/simple-wordpress-docker

Repository files navigation

Simple Wordpress Docker Setup

This repository contains a Docker setup for running a WordPress site. It includes a Dockerfile that sets up a WordPress server and an init.sql script that initializes the WordPress database.

Info : The worpress in the container is a pre-build image so the user, password, language, front page and the first article has been already set. You can modify is in the settings of wordpress.

GitHub Release GitHub License GitHub last commit (by committer) GitHub Downloads (all assets, all releases)

How It Works

The Dockerfile starts from the ubuntu:jammy base image and installs necessary software including Nginix and PHP 8.3. It then copies the WordPress files into the /var/www/wordpress/ directory in the container and sets up Nginx and PHP to serve the WordPress site.

The init.sql script is run when the container starts up to initialize the WordPress database. It replaces all instances of http://localhost with the value of the WORDPRESS_HOST environment variable in the SQL dump.

How to Run

To run a container from the image, use the following command:

docker run -d --name wordpress \
    -e WORDPRESS_DATABASE_HOST=your-database-host \
    -v /path/to/volume/:/var/www/wordpress \
    -p 80:80 \
    nayeonyny/wordpress:latest

Example :

docker run -d --name wordpress -p 80:80 -e WORDPRESS_DATABASE_HOST=172.28.6.193 -v /home/probu/wptest:/var/www/wordpress nayeonyny/wordpress:latest

Environment Variables

The following environment variables can be set when running the Docker container:

ENV Default value Example Description
WORDPRESS_DATABASE wordpress mydatabase The name of the WordPress database.
WORDPRESS_DATABASE_USER wpuser myuser The username for the WordPress database.
WORDPRESS_DATABASE_PASSWORD wpuser mypassword The password for the WordPress database.
WORDPRESS_DATABASE_HOST localhost example.com or 64.23.50.120 The ip address of the WordPress database, can be private, public or you can use a domain.
WORDPRESS_HOST localhost example.com or 64.23.50.120 The host of your WordPress site. If this is not set or is empty, it will default to localhost. This means that all resources will only be available on localhost. To make your WordPress site work online, change this variable to the public IP address or domain name of your host.
WORDPRESS_COMPOSE false true If you use this image in a docker compose, you must set this variable to true, this will delay wordpress startup to allow the database container to initialize and avoid the database not found error on wordpress.

⚠️ Important : The var WORDPRESS_DATABASE_HOST it can't be localhost you must change this variable or the container will be stopped, if you have a database container change to host or container ip. ⚠️

How to do :

This provides the IP address of your database container.

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

Health Check

The Dockerfile includes a health check that sends a request to http://localhost/ every 5 minutes. If the request is successful (i.e., the HTTP status code is 200), the container is considered healthy. If the request is not successful, the container is considered unhealthy.

Author

License

Copyright (C) 2024 Ethan Besson

Licensed under the Academic Free License version 3.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://opensource.org/license/afl-3-0-php/

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.