Docker Community Forums

Share and learn in the Docker community.

Docker-compose file to setup a Ecommerce site using drupal

I want to build a an Ecommersite site using drupal. To do so i need a docker-compose file to create a drupal-ecommerce instance that includes orders, products,configuration etc.

There are several ways to go about building containers, but we’re going to use the excellent Docker Compose tool.
First, open a terminal, create a directory for your WordPress installation, and change to that directory:

mkdir testing-wordpress && cd testing-wordpress
Next, create the file we’ll use to tell Docker Compose what to do:

touch docker-compose.yml
We’re going to use the Docker Compose file from the official Compose documentation. Open “docker-compose.yml” in a text editor and paste the following text into it:

version: ‘3’

services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- “8000:80”
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
If you’re interested in what the file is doing, I encourage you to read the documentation, but, in brief, it tells Docker Compose to create two containers. The first is a container for the MySQL database, and the second is a container for WordPress itself.
Save the file, go back to your terminal, and run this command:

docker-compose up -d
Docker will download, configure, and launch the containers. It might take a few minutes, but when it’s finished, you’ll have a WordPress instance waiting at this URL:

http://localhost:8000
To stop the containers, use this command from inside the project folder:

docker-compose stop
You can restart with the “up” command you used previously.
If you want to remove the WordPress container, but leave the database intact:

docker-compose down
And if you want to blow away both WordPress and the database container:

docker-compose down --volumes
After removing the containers, you can start from scratch with the same “up” command as before:

docker-compose up -d
Because Docker containers are entirely self-contained, you can create as many WordPress installations as you like: just create a new folder, copy the “docker-compose.yml file to it, and repeat the process.