Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you create and start all the services from your configuration.
Compose is great for development, testing, and staging environments, as well as CI workflows. Install docker, docker-compose with my previous blog.
Installing docker-compose
Use the below command to install docker-checking version
krishna@ubuntu:~$ docker-compose --version docker-compose version 1.12.0, build b31ff33
Docker Compose Config
Create an empty project directory say “mywordpress” and within this directory create docker-compose.yml file, that will start the wordpress blog.
krishna@krishna-VirtualBox:~/mywordpress$ cat docker-compose.yml
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: P@55w0rD
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:
krishna@krishna-VirtualBox:~/mywordpress$ docker-compose up -d
Creating network "mywordpress_default" with the default driver
Creating volume "mywordpress_db_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
cd0a524342ef: Pull complete
d9c95f06c17e: Pull complete
46b2d578f59a: Pull complete
10fbc2bcc6e9: Pull complete
91b1a29c3956: Pull complete
5bf9316bd602: Pull complete
69bd23f08b55: Pull complete
4fb778132e94: Pull complete
6913628d7744: Pull complete
a477f36dc2e0: Pull complete
c954124ae935: Pull complete
Digest: sha256:e44b9a3ae88db013a3e8571a89998678ba44676ed4ae9f54714fd31e108f8b58
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
cd0a524342ef: Already exists
14b8a88a0af0: Pull complete
d78c922dd678: Pull complete
6680e61553d3: Pull complete
df1ddb74fbec: Pull complete
048af0e09526: Pull complete
d11ab6756039: Pull complete
8b684f7dda23: Pull complete
206854c69eb7: Pull complete
b7e643dc9b09: Pull complete
b9503d4d2386: Pull complete
f31ae3e5fa86: Pull complete
44fd64f7b16f: Pull complete
0b10d49f9584: Pull complete
a59a3f4f432b: Pull complete
d5fad60b1fb1: Pull complete
6762d0157c35: Pull complete
08dc92905b0e: Pull complete
Digest: sha256:dc77678ddced9623331e051e1b192ee76f887fd683b9ede2f718a6bc4eb08ea6
Status: Downloaded newer image for wordpress:latest
Creating mywordpress_db_1
Creating mywordpress_wordpress_1
krishna@krishna-VirtualBox:~/mywordpress$
WordPress in Browser
Open up a link in browser http://machine-ip:8000

Conclusion
hooray… successfully, installed wordpress with docker-compose.

krishna@ubuntu:~/myproject$ cat docker-compose.yml
version: ‘3’
services:
db:
image: percona/percona-server:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: Cisco@123
ports:
– “3306”
volumes:
– /var/lib/mysql
krishna@ubuntu:~/myproject$