How to install Wordpress using Docker Compose on Ubuntu 21.04

To Install Wordpress using Docker Compose on Ubuntu 21.04

Introduction:

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker Compose is a tool that helps define, share, and encapsulate multi-container applications based on YAML files that are coded in YAML files.

Installation Procedure:

Step 1: Check the OS version by using the below command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Step 2: Update the repository source list by using the below command

root@linuxhelp:~# apt update 
Hit:1 http://in.archive.ubuntu.com/ubuntu hirsute InRelease
Hit:2 https://download.docker.com/linux/ubuntu bionic InRelease                                                              
Hit:3 http://in.archive.ubuntu.com/ubuntu hirsute-updates InRelease                                                          
Hit:4 http://in.archive.ubuntu.com/ubuntu hirsute-backports InRelease       
Hit:5 http://security.ubuntu.com/ubuntu hirsute-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
1 package can be upgraded. Run 'apt list --upgradable' to see it.

Step 3: Install “python3-pip” package by using the below command

root@linuxhelp:~# apt install python3-pip -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  libllvm11
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential dpkg-dev fakeroot g++ g++-10 gcc gcc-10
  javascript-common libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan6 libatomic1 libbinutils
  libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libexpat1-dev libfakeroot libgcc-10-dev
  libitm1 libjs-jquery libjs-sphinxdoc libjs-underscore liblsan0 libnsl-dev libpython3-dev libpython3.9-dev libquadmath0
  libstdc++-10-dev libtirpc-dev libtsan0 libubsan1 linux-libc-dev lto-disabled-list make manpages-dev python-pip-whl
  python3-dev python3-distutils python3-lib2to3 python3-setuptools python3-wheel python3.9-dev rpcsvc-proto zlib1g-dev
Suggested packages:
  binutils-doc debian-keyring g++-multilib g++-10-multilib gcc-10-doc gcc-multilib autoconf automake libtool flex bison
After this operation, 216 MB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu hirsute/main amd64 binutils-common amd64 2.36.1-6ubuntu1 [217 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu hirsute/main amd64 libbinutils amd64 2.36.1-6ubuntu1 [584 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu hirsute/main amd64 libctf-nobfd0 amd64 2.36.1-6ubuntu1 [97.8 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu hirsute/main amd64 libctf0 amd64 2.36.1-6ubuntu1 [95.0 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu hirsute/main amd64 binutils-x86-64-linux-gnu amd64 
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
Setting up python3.9-dev (3.9.5-3ubuntu0~21.04.1) ...
Setting up build-essential (12.8ubuntu3) ...
Setting up libpython3-dev:amd64 (3.9.4-1) ...
Setting up python3-dev (3.9.4-1) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.33-0ubuntu5) ...

Step 4: Install docker-compose” using pip3 by using the below command

root@linuxhelp:~# pip3 install docker-compose 
Collecting docker-compose
  Downloading docker_compose-1.29.2-py2.py3-none-any.whl (114 kB)
     |████████████████████████████████| 114 kB 1.3 MB/s 
Collecting websocket-client<1,>=0.32.0
  Downloading websocket_client-0.59.0-py2.py3-none-any.whl (67 kB)
     |████████████████████████████████| 67 kB 2.9 MB/s 
Collecting docker[ssh]>=5
  Downloading docker-5.0.3-py2.py3-none-any.whl (146 kB)
     |████████████████████████████████| 146 kB 7.6 MB/s 
  Downloading pyrsistent-0.18.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (115 
     |████████████████████████████████| 61 kB 390 kB/s 
Requirement already satisfied: pynacl>=1.0.1 in /usr/lib/python3/dist-packages (from paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (1.4.0)
Requirement already satisfied: cryptography>=2.5 in /usr/lib/python3/dist-packages (from paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (3.3.2)

  Stored in directory: /root/.cache/pip/wheels/70/4a/46/1309fc853b8d395e60bafaf1b6df7845bdd82c95fd59dd8d2b
Successfully built dockerpty docopt
Installing collected packages: pycparser, cffi, websocket-client, bcrypt, pyrsistent, paramiko, docker, attrs, texttable, python-dotenv, jsonschema, docopt, dockerpty, docker-compose

Successfully installed attrs-21.4.0 bcrypt-3.2.0 cffi-1.15.0 docker-5.0.3 docker-compose-1.29.2 dockerpty-0.4.1 docopt-0.6.2 jsonschema-3.2.0 paramiko-2.9.2 pycparser-2.21 pyrsistent-0.18.1 python-dotenv-0.19.2 texttable-1.6.4 websocket-client-0.59.0

Step 5: Create a directory for wordpress by using the below command

root@linuxhelp:~# mkdir wordpress

Step 6: Change the directory to wordpress directory by using the below command

root@linuxhelp:~#  cd wordpress/

Step 7: Create a docker-compose file by using the below command

root@linuxhelp:~/wordpress# vi docker-compose.yml

Step 8: Execute the docker-compose file by using the below command

root@linuxhelp:~/wordpress# docker-compose up 
Creating network "wordpress_default" with the default driver
Creating volume "wordpress_db_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
72a69066d2fe: Pull complete
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
a2abf6c4d29d: Pull complete
c5608244554d: Pull complete
2d07066487a0: Pull complete
1b6dfaf1958c: Pull complete
32c5e6a60073: Pull complete
90cf855b27cc: Pull complete
271be7ae0cc8: Pull complete
Digest: sha256:7c33c72f1aba217fd5554d5dbc7dbad3274962c5602da353a6196db1241cd05a
Status: Downloaded newer image for wordpress:latest
Creating wordpress_db_1 ... done
Creating wordpress_wordpress_1 ... done
Attaching to wordpress_db_1, wordpress_wordpress_1
db_1         | 2022-01-17 23:13:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
db_1         | 2022-01-17 23:13:38+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1         | 2022-01-17 23:13:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
db_1         | 2022-01-17 23:13:38+00:00 [Note] [Entrypoint]: Initializing database files
db_1         | 2022-01-17T23:13:38.777391Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is
. Please use TLSv1.2 or higher.
db_1         | 2022-01-17T23:13:54.009038Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2022-01-17T23:13:54.009042Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2022-01-17T23:13:54.010885Z 0 [Warning] CA certificate ca.pem is self signed.
db_1         | 2022-01-17T23:13:54.011230Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1         | 2022-01-17T23:13:54.012371Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1         | 2022-01-17T23:13:54.014281Z 0 [Note] IPv6 is available.
db_1         | 2022-01-17T23:13:54.019168Z 0 [Note]   - '::' resolves to '::';
db_1         | 2022-01-17T23:13:54.019833Z 0 [Note] Server socket created on IP: '::'.
db_1         | 2022-01-17T23:13:54.023143Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1         | 2022-01-17T23:13:54.056152Z 0 [Note] Event Scheduler: Loaded 0 events
db_1         | 2022-01-17T23:13:54.058323Z 0 [Note] mysqld: ready for connections.
db_1         | Version: '5.7.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

Step 9: Ping http://localhost:8000 in browser as shown in the below image

Step 10: Create and Login with Admin User as shown in the below image

Step 11: This is the Dashboard page of the Wordpress

By this to install Wordpress using Docker Compose on Ubuntu 21.04 have been completed

Tag : Docker
FAQ
Q
How to combine multiple Docker compose files?
A
To combine multiple Docker compose files by using "docker-compose -f file1 -f file2"
Q
How to view logs in Docker?
A
To view, the logs in Docker use the command "docker logs -f"
Q
How to Specify an alternate compose file?
A
To Specify an alternate compose file use the command "docker-compose -f"
Q
How to uninstall Docker Compose if you installed using curl?
A
If you installed Docker Compose using curl, uninstall it with "sudo rm /usr/local/bin/docker-compose"
Q
How to install Docker Compose using curl?
A
To Install Docker Compose using curl "sudo curl -L "https://github.com/docker/compose/releases/download/v1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose"