The following Docker Compose can be used to create persistent MySQL and WordPress instances, save the compose within its own directory on your Docker host and execute the project using the command:
docker-compose up -d
The WordPress environment will be available on http://<IP address of Docker Host>:8082 – published port can be changed by modification of the compose file.
Compose file – note you will need to provide secure MySQL and WordPress DB passwords:
version: '2' services: wp-mysql: image: mysql:latest volumes: - wp_mysql:/var/lib/mysql ports: - "3306:3306" restart: always environment: MYSQL_ROOT_PASSWORD: "<mysql_root_password>" MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: "<wordpressdb_password>" wp-wordpress: depends_on: - wp-mysql image: wordpress:latest volumes: - wp_data:/var/www/html/wp-content ports: - "8082:80" restart: always environment: WORDPRESS_DB_HOST: wp-mysql:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: "<wordpressdb_password_as_above>" volumes: wp_mysql: wp_data:
To stop the containers brought up by compose relating to this project:
docker-compose down
To stop the containers and cleanup volumes (thus losing data contained within them):
docker-compose down --volumes