Docker enables to separate your applications from your infrastructure so you can deliver software quickly.
This post aims to setup WordPress with Docker Compose. Why Docker Compose?
With Compose, you use a YAML file to configure your application’s services.
docker-compose.yaml or docker-compose.yml is file where services are defined. So, lets crack the nuts.
I am using Ubuntu.
First step: Install docker
- Update apt:
sudo apt-get update
- Install required packages for docker.
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
- Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- Use the following command to set up the stable repository.
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null - Then, update again:
sudo apt-get update
- Install docker:
sudo apt-get install docker-ce docker-ce-cli containerd.io
Step 2: Install Docker compose
- Run this command to download the current stable release of Docker Compose using curl:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
Step 3: Install WordPress container in Docker ship
- Make a directory for docker use.
mkdir wp-docker
- Go to this directory.
cd wp-docker
- Make a file named docker-compose.yml ( file extension can be .yml or .yaml ).
touch docker-compose.yml
- Open docker-compose.yml in any editor and write the following code. Note that: YAML file is space sensitive.
version: "3.9" 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 phpmyadmin: image: phpmyadmin restart: always ports: - 8080:80 environment: - PMA_ARBITRARY=1 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 WORDPRESS_DB_NAME: wordpress volumes: ["./:/var/www/html"] volumes: db_data: {}
5. Run docker-compose up -d
to run docker-compose file with detaching mode.
6. Go to localhost:8000 in the browser. Setup the famous WordPress installation.
7. Go to localhost:8080 in the browser. We have nothing to do with the server field. Enter user: wordpress and pass: wordpress. We found every data in wordpress database.