Sign inSign up

fcarneiro/wordpress

By fcarneiro

•Updated about 4 years ago

Based on the official WordPress image, without the nasty VOLUME and the download on startup.

Image
0

7.1K

fcarneiro/wordpress repository overview

⁠About this Image

This image is based on the official image of WordPress from Docker Hub (https://hub.docker.com/_/wordpress⁠) but, without the nasty VOLUME on /var/www/html/ and the ineficeent download of wordpress.zip during startup.

Also, it has wp-cli (https://wp-cli.org/⁠) already installed.

⁠How to use this image

WordPress requires access to a MySQL or MariaDB database to store information.

Also the contents of the uploads directory (/var/www/html/wp-content/uploads/) should be persisted with a volume. I recommend to add your themes and plugins on your Dockerfile or in a build script, otherwise you'll need to persist the full /var/www/html/wp-content/ directory.

To test if the image works, just run a new conteiner with standard port mappings⁠ and without a database or volumes:

$ docker run -d -p 8080:80 fcarneiro/wordpress

Then, access it via http://localhost:8080⁠ or http://host-ip:8080⁠ in a browser.

When you finish testing, don't forget to stop your container⁠.

⁠Using Docker Compose

You can use a Docker Compose file like the one below to add other feature:

version: '3.4'

services:

  web:
    image: fcarneiro/wordpress:latest
    restart: always
    ports:
      - "8080:80"
    networks:
      backend:
    volumes:
      - uploads:/var/www/html/wp-content/uploads/
    environment:
      WORDPRESS_DB_HOST: wordpress_db:3306
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: MyPassword
      WORDPRESS_TABLE_PREFIX: wp_
    depends_on:
      - db
     
  db:
    image: mysql:5.7
    restart: always
    networks:
      backend:
        aliases:
          - 'wordpress_db'
    volumes:
      - data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: MyRootPassword
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: MyPassword

volumes:
  uploads:
  data:

networks:
  backend:
    driver: bridge

Save this code in a docker-compose.yml file and then run wordpress with a mysql database:

$ docker-compose up -d

Then, access it via http://localhost:8080⁠ or http://host-ip:8080⁠ in a browser.

To stop the containers, execute:

$ docker-compose down

The database files and the wordpress uploads folder are persisted in named volumes (data and uploads)!

⁠Configuration

⁠Environment variables

The WordPress instance can be customized by specifying environment variables. The following environment values are provided to custom WordPress:

  • WORDPRESS_DB_HOST
  • WORDPRESS_DB_NAME
  • WORDPRESS_DB_USER
  • WORDPRESS_DB_PASSWORD
  • WORDPRESS_TABLE_PREFIX
  • WORDPRESS_AUTH_KEY, WORDPRESS_SECURE_AUTH_KEY, WORDPRESS_LOGGED_IN_KEY, WORDPRESS_NONCE_KEY, WORDPRESS_AUTH_SALT, WORDPRESS_SECURE_AUTH_SALT, WORDPRESS_LOGGED_IN_SALT, WORDPRESS_NONCE_SALT (default to unique random SHA1s, but only if other environment variable configuration is provided)
  • WORDPRESS_DEBUG (defaults to disabled, non-empty value will enable WP_DEBUG in wp-config.php)
  • WORDPRESS_CONFIG_EXTRA (defaults to nothing, non-empty value will be embedded verbatim inside wp-config.php -- especially useful for applying extra configuration values this image does not provide by default such as WP_ALLOW_MULTISITE)

This would be an example of a configuration with an external database:

$ docker run -d --name my_wordpress \
  -p 8080:80 -p 8443:443 \
  --network wordpress-network \
  --env WORDPRESS_DB_HOST=wordpress_db \
  --env WORDPRESS_DB_NAME=wordpress \
  --env WORDPRESS_DB_USER=wordpress \
  --env WORDPRESS_DB_PASSWORD=MyPassword \
  --env WORDPRESS_TABLE_PREFIX=wp_ \
  --volume wordpress_uploads:/var/www/html/wp-content/uploads/ \
  fcarneiro/wordpress:latest

⁠WP-CLI tool

This WordPress image includes the command line interface wp-cli that can help you to manage and interact with your WP sites.

This would be an example of using wp-cli to display the list of wordpress users:

$ docker exec -it my_wordpress wp user list --allow-root

Find more information about parameters available in the tool in the official documentation⁠.

Tag summary

Content type

Image

Digest

sha256:299148ad2…

Size

206.3 MB

Last updated

about 4 years ago

docker pull fcarneiro/wordpress