Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Setup for using Docker containers with Wordpress and MYSQL
- - New application
- - Run command
- - `docker-compose up -d`
- - Existing application
- - To ensure database container is loaded before Wordpress container is started
- you **MUST** start containers individually the first time development environment is setup
- - Start database container
- - `docker-compose up -d db - Replace db with the name of your database container`
- - Wait until database is running and loaded (10s is usually more than enough time)
- - Start your wordpress container
- - `docker-compose up -d wordpress - Replace db with the name of your database container`
- --
- ```
- # Refers to the docker-compose production version
- version: '3.3
- # Services are containers in production you would like to pull from
- services:
- # Database container config
- db:
- # Pulls the latest stable version of mysql
- # Change latest to specific version if needed (ie - mysql:version#)
- image: mysql:5.7.17
- # Creates a directory called db_data to store database information
- volumes:
- # creates new db located in the db_data directory
- - ./db:/var/lib/mysql
- # Load existing db from dump file located in this directory
- - "./db_data:/docker-entrypoint-initdb.d"
- ports:
- - "3306:3306"
- # Database container is always set to restart when start command entered
- restart: always
- # Set up specific variables for the database container
- # These must be the same as the Wordpress credentials to ensure database accessibility
- environment:
- MYSQL_ROOT_PASSWORD: root
- MYSQL_DATABASE: database name
- MYSQL_USER: user name
- MYSQL_PASSWORD: user password
- # Wordpress container config
- wordpress:
- # Will not start wordpress container unless db is up and running
- depends_on:
- - db
- # Pulls the latest stable version of wordpress
- # Change latest to specific version if needed (ie - wordpress:version#)
- image: wordpress:latest
- # Creates a directory called wordpress to store site information
- volumes:
- - "./wordpress:/var/www/html"
- # Set a port to expose the container to (ie - localhost:8000)
- ports:
- - "8000:80"
- # Database container is always set to restart when start command entered
- restart: always
- # Set up specific variables for the Wordpress container
- # WARNING - These will override settings you have in wp-config file
- environment:
- WORDPRESS_DB_HOST: db
- WORDPRESS_DB_NAME: database name
- WORDPRESS_DB_USER: user name
- WORDPRESS_DB_PASSWORD: user password
- # **Optional**
- # If set will make mounted volume data persistent
- volumes:
- db_data:
- ```
Add Comment
Please, Sign In to add comment