Replace new-folder-name with your desired folder name. This will not affect the functionality of the Docker setup or the WordPress environment.
This section will guide you on how to use Docker Compose for setting up a WordPress environment.
- Ensure you have Docker and Docker Compose installed on your machine.
If you haven't already, clone the repository:
git clone https://github.com/Zagaz/Wordpress-Docker-Environment.git
cd WordPress-Docker-EnvironmentAfter cloning the repository, you can change the folder name to suit your preferences. Simply navigate to the parent directory and rename the folder using the following command:
# (Optional) Navigate to the parent directory, if needed.
cd ..
#Once you are in the parent directory, rename the folder
mv WordPress-Docker-Enviroment <new-folder-name>
- Open the
docker-compose.yamlfile to configure your services. You can specify the WordPress version, database settings, and other configurations.
- To start your WordPress environment, run:
docker-compose up -dThis command will start the containers in detached mode.
- To stop your WordPress enviroment, run:
docker-compose down- Once the containers are running, you can access your WordPress site by navigating to
http://localhost:8000in your web browser.
-
- Once the containers are running, you can access your WordPress site by navigating to
http://localhost:8081in your web browser.
- Once the containers are running, you can access your WordPress site by navigating to
- Login: wp_user (Default)
- Password: wp_password (Default)
You can change this credentials at .env file. - MYSQL_USER=wp_user
- MYSQL_PASSWORD=wp_password
- To stop the running services, use:
docker-compose down- To delete the Docker environment completely, you can run:
docker-compose down --volumesThis command will stop the containers and remove the associated volumes, effectively deleting the environment.
This environment uses Docker images for WordPress, the database, and phpMyAdmin. By default, these images are defined in the docker-compose.yaml file using environment variables from your .env file.
- WordPress:
${WORDPRESS_IMAGE}(Default:wordpress:latest) - Database:
${MYSQL_IMAGE}(Default:mariadb:latest) - phpMyAdmin:
${PHPMYADMIN_IMAGE}(Default:phpmyadmin/phpmyadmin:latest)
To use a different image or version, edit the corresponding variable in your .env file:
WORDPRESS_IMAGE=wordpress:latest
MYSQL_IMAGE=mariadb:latest
PHPMYADMIN_IMAGE=phpmyadmin/phpmyadmin:latestFor example, to use MySQL instead of MariaDB, set:
MYSQL_IMAGE=mysql:latestAfter making changes, restart your containers:
docker compose down
docker compose up -dThis will apply your new image settings.
The default data in the .env file is provided to help you get started with your WordPress Docker environment. You can change these values as desired to suit your specific configuration needs.
.env file, especially regarding sensitive data such as database credentials, API keys, and other private information. Ensure that sensitive data is kept secure and not exposed in public repositories or shared environments.
You have successfully set up a WordPress environment using Docker Compose!
When you add files or create folders inside the wp-content directory on the host (for example wp-content/plugins or wp-content/themes), you may need admin privileges because the directory or files can be owned by root or by the webserver user inside the container. Below are a few safe options to add content:
- Create folders/files using sudo (quick, but requires admin rights):
sudo mkdir -p wp-content/plugins/my-plugin
sudo touch wp-content/plugins/my-plugin/my-plugin.php- Give your user ownership of the folder (recommended if you will frequently add/edit files locally):
sudo chown -R $(id -u):$(id -g) wp-content- Copy files into the running container (no host permission changes required):
docker compose exec wordpress mkdir -p /var/www/html/wp-content/plugins/my-plugin
docker cp ./local/path/to/my-plugin wordpress:/var/www/html/wp-content/plugins/my-pluginNote: Changing ownership or permissions affects security. Prefer chown to set ownership to your user if you plan to edit files locally. If you only need to add files occasionally, sudo or docker cp are convenient alternatives.
- Clone the repo and enter the folder:
git clone https://github.com/Zagaz/Wordpress-Docker-Enviroment.git
cd wordpress-docker-enviroment-
Edit
.envif you want to change default images or credentials (e.g.WORDPRESS_IMAGE,MYSQL_IMAGE,PHPMYADMIN_IMAGE,MYSQL_USER,MYSQL_PASSWORD). -
Start the stack:
docker compose up -d- Stop the stack:
docker compose down- Remove containers + volumes (delete environment):
docker compose down --volumes-
Access:
- WordPress: http://localhost:8000
- phpMyAdmin: http://localhost:8081 (default login:
wp_user/wp_passwordunless changed in.env)
-
Need to add files to
wp-content?- Use
sudoto create files, or change ownership to your user:
- Use
sudo chown -R $(id -u):$(id -g) wp-content- Or copy files into the running container to avoid changing host permissions:
docker compose exec wordpress mkdir -p /var/www/html/wp-content/plugins/my-plugin
docker cp ./local/path/to/my-plugin wordpress:/var/www/html/wp-content/plugins/my-pluginThis TL;DR covers the most common commands for install, start, stop, access, and handling wp-content permissions.