For most of my WordPress projects I use my own Alcedo WordPress workflow. With some extra scripts, creating a new site is as easy as running 'create site.c7'
in the terminal. This sets up a full WordPress install with local domains and certificates.
But, in this case i’m using a different setup in which I use the default wordpress:php8.0
docker image. As i’m using the standard setup, I also wanted to use the default wordpress:cli
docker image.
How does that work?
As they say, an image says more then a thousands words. But, since text in images can’t be copied, I’ll copy/paste the two services below:
wp:
container_name: ${NAME}-wp
depends_on:
- db
image: wordpress:php8.0
user: 1000:1000
volumes:
- ./app/www/content/plugins:/var/www/html/wp-content/plugins
- ./app/www/content/mu-plugins:/var/www/html/wp-content/mu-plugins
- ./app/www/content/themes:/var/www/html/wp-content/themes
- uploads:/var/www/html/wp-content/uploads:rw
- wordpress:/var/www/html
ports:
- "8000:80"
environment:
WORDPRESS_DB_HOST: ${NAME}-db:3306
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
WORDPRESS_DB_NAME: ${DB_NAME}
WORDPRESS_DEBUG: 1
VIRTUAL_HOST: "${SITE_DOMAIN}" # Used for nginx-proxy
VIRTUAL_PORT: 80 # Used for nginx-proxy
LETSENCRYPT_HOST: "${SITE_DOMAIN}" # Used for nginx-proxy
WORDPRESS_CONFIG_EXTRA: |
/* Multisite */
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', true );
define( 'DOMAIN_CURRENT_SITE', 'sitec7' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
expose:
- "80"
wpcli:
container_name: ${NAME}-cli
depends_on:
- wp
image: wordpress:cli
user: 1000:1000
command: tail -f /dev/null
volumes:
- wordpress:/var/www/html
environment:
WORDPRESS_DB_HOST: ${NAME}-db:3306
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
WORDPRESS_DB_NAME: ${DB_NAME}
profiles:
- dev
As you see, both images use the same volume and environment setup. This allows you to run commands like:
docker exec site-cli wp --info
and
docker exec site-cli wp search-replace "test" "test1" --dry-run
Want to make it even easier? Set an alias for docker exec site-cli wp
so that you can run something like sitewp --info
. In my own development environment, my folders are named the same as my container. When you change directory, and the directory has an .env
file, an alias is set for wp
and links to the correct container.
Happy developing!
Leave a Reply