Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to Install WordPress and PhpMyAdmin using Docker Compose (CentOS 7)  (Read 57889 times)

0 Members and 1 Guest are viewing this topic.

akhilu

  • Guest
Docker is a lightweight container system that lets you run an application in a container, which is like virtual machine. You can refer the below steps to install docker on CentOS 7 and then set up a WordPress instance using a docker file.

Access your server via CLI and run below command to update package database

Code: [Select]
yum check-update
Run the below command to add official Docker repository, download and install the latest version of Docker:

Code: [Select]
curl -fsSL https://get.docker.com/ | sh

Once the installation is over run the below command to start the Docker service

Code: [Select]
systemctl start docker
Verify that the service is active

Code: [Select]
systemctl status docker
Output:

Code: [Select]
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2018-11-18 08:29:49 UTC; 10s ago
     Docs: https://docs.docker.com
 Main PID: 4352 (dockerd)
    Tasks: 18
   Memory: 55.7M
   CGroup: /system.slice/docker.service
           ├─4352 /usr/bin/dockerd -H unix://
           └─4363 containerd --config /var/run/docker/containerd/containerd.toml --log-level info
           
           

Please Note: Most of the cloud service like DigitalOcean and AWS etc offers OS  images that comes with Docker preinstalled. Hence you are using cloud hosting service like AWS, DiditalOcean then you can use the Docker image while deploying the server so that you do not have to do the above steps manually.

Once the Docker is installed you can use the below command to check the Docker version

Code: [Select]
docker version
Output:

Code: [Select]
Client:
 Version:           18.09.0
 API version:     1.39
 Go version:      go1.10.4
 Git commit:      4d60db4
 Built:                Wed Nov  7 00:48:22 2018
 OS/Arch:          linux/amd64
 Experimental:   false

Server: Docker Engine - Community
 Engine:
  Version:            18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:                 Wed Nov  7 00:19:08 2018
  OS/Arch:          linux/amd64
  Experimental:   false


Now that Docker is installed we need to install Docker-Compose. Please install python-pip as prerequisite using below commands:

Code: [Select]
yum install epel-release
yum install -y python-pip

Then you can install Docker Compose:

Code: [Select]
pip install docker-compose
Once docker compose is installed we need to create a new folder for WordPress installation and move into the folder. Please use the below command:

Code: [Select]
mkdir ~/wordpress && cd $_
Now use the below command to create a docker compose yml file for WordPress installation

Code: [Select]
vim docker-compose.yml

Then pase the below content into the yml file and save it.

Code: [Select]
version: '2'
services:
  wordpress:
    depends_on:
      - db
    image: wordpress:4.7.1
    restart: always
    volumes:
      - ./wp-content:/var/www/html/wp-content
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_PASSWORD: p4ssw0rd!
    ports:
      - 80:80 # Expose http and https
      - 443:443
    networks:
      - back
  db:
    image: mysql:5.7
    restart: always
    volumes:
       - ./db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: p4ssw0rd!
    networks:
      - back
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - 8080:80
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: p4ssw0rd!
    networks:
      - back
networks:
  back:
volumes:
  db_data:

Please Note The above code will download docker images of WordPress 4.7.1, MySQL 5.7 and PhpMyAdmin images from docker repository and run it.

Please Note It will also create folder ./db_data and ./wp-content  in the wordpress directory that we created earlier and sync the wp-content folder and the database contact into it. This will help us save website data on the server so that even if we remove the containers later the website data will be still safe on the server.

You can use the below command to execute the Docker compose file

Code: [Select]
docker-compose up -d
Output:

Code: [Select]
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
a5a6f2f73cd8: Pull complete
936836019e67: Pull complete
283fa4c95fb4: Pull complete
1f212fb371f9: Pull complete
e2ae0d063e89: Pull complete
5ed0ae805b65: Pull complete
0283dc49ef4e: Pull complete
a7905d9fbbea: Pull complete
cd2a65837235: Pull complete
5f906b8da5fe: Pull complete
e81e51815567: Pull complete
Pulling wordpress (wordpress:4.7.1)...
4.7.1: Pulling from library/wordpress
5040bd298390: Pull complete
568dce68541a: Pull complete
6a832068e64c: Pull complete
3b0f3d176a5b: Pull complete
20cc248a5690: Pull complete
6ff565538ee6: Pull complete
9f1077228581: Pull complete
57359f144a19: Pull complete
9754ef36b033: Pull complete
e156df35b624: Pull complete
df09daa2224a: Pull complete
bfa0d8031302: Pull complete
fe629d500af7: Pull complete
2761420c8e70: Pull complete
71580740e433: Pull complete
22ff3670a5e6: Pull complete
39f4427993e5: Pull complete
9ab2843f4934: Pull complete
Pulling phpmyadmin (phpmyadmin/phpmyadmin:)...
latest: Pulling from phpmyadmin/phpmyadmin
911c6d0c7995: Pull complete
2527cc05836d: Pull complete
3299172a2d6d: Pull complete
05782106624f: Pull complete
3e3261543ec8: Pull complete
ce1c845d4246: Pull complete
e005e70f55dc: Pull complete
84403a106e16: Pull complete
e4fc13f7949f: Pull complete
2a53e72ea7b9: Pull complete
d791f6b71f27: Pull complete
576bdfd7cc75: Pull complete
20768032f0fb: Pull complete
fc8aa3d46064: Pull complete
bade7addd704: Pull complete
4b30a4dd0b24: Pull complete
b02d6e91d2b5: Pull complete
Creating wordpress_db_1_56e97f6fca35 ... done
Creating wordpress_phpmyadmin_1_45b68f706ee4 ... done
Creating wordpress_wordpress_1_f11d769b43d1  ... done

You can run the below command to see the list of containers that are running on the server:

Code: [Select]
docker ps
Output:
Code: [Select]
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                                      NAMES
e0fcb5383ea3        phpmyadmin/phpmyadmin   "/run.sh supervisord…"   23 minutes ago      Up 23 minutes       9000/tcp, 0.0.0.0:8080->80/tcp             wordpress_phpmyadmin_1_5cb4745b8656
d97b84e9174f        wordpress:4.7.1         "docker-entrypoint.s…"   23 minutes ago      Up 23 minutes       0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   wordpress_wordpress_1_ae4ee5d1d3b1
f87672746548        mysql:5.7               "docker-entrypoint.s…"   23 minutes ago      Up 23 minutes       3306/tcp, 33060/tcp                        wordpress_db_1_67afaa299feb

Run the below command to see the list of images downloaded by the docker compose the file.

Code: [Select]
docker images -a
Output:
Code: [Select]
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
mysql                   5.7                 ae6b78bedf88        2 days ago          372MB
phpmyadmin/phpmyadmin   latest              126b8717cebb        2 months ago        166MB
wordpress               4.7.1               dfbefe759772        22 months ago       400MB

You can then access the server IP to start the WordPress installation. Please refer the below image: