Latest Posts

Using My Own Docker Images to Create Wordpress Site in Portainer

This post records all steps to set up a Wordpress site in a cloud Linux server with Docker and Portaner technologies. 


Install Docker in Ubuntu or CentOS


For CentOS:

sudo -i
yum -y update
curl -sSL https://get.docker.com/ | sh
systemctl start docker.service
systemctl enable docker.service


For Ubuntu

sudo apt update
sudo apt upgrade
sudo apt install docker.io -y
sudo -i
systemctl start docker
systemctl enable docker
docker version


Install Portainer 


docker volume create portainer_data
docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
docker ps
Use your browser to access URL http://<public ip of your linuxserver>:9000
First time, it will ask you to set up admin user's password.



Create Wordpress Container



Change wp1 network to wp1 as well. Make sure restart policy is always. 


Actually, wp1 container does not has to be configured into user defined network wp1. It can be in system default bridge network.


[email protected]:/var/www/html# ls
index.php    wp-activate.php     wp-comments-post.php  wp-content   wp-links-opml.php  wp-mail.php      wp-trackback.php
license.txt  wp-admin            wp-config-sample.php  wp-cron.php  wp-load.php        wp-settings.php  xmlrpc.php
readme.html  wp-blog-header.php  wp-config.php         wp-includes  wp-login.php       wp-signup.php
[email protected]:/var/www/html# nano wp-config.php



/ ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'root' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password' );

/** MySQL hostname */
define( 'DB_HOST', '172.20.0.200' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );



Create MySQL Container



For mysql1 container, join it into same network as wp1, which is network wp1. Also change ipv4 address to 172.20.0.200


Since I would like to set static ip 172.20.0.200, mysql1 container has to be put into a user defined network, such as wp1. 

Log into console and connect mysql from command line. Create a database which name is wordpress.

[email protected]:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 39
Server version: 8.0.21 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
5 rows in set (0.00 sec)

Default username and password: root / password

Database name is wordpress.



Create Nginx Container




Nginx is using Bridge network. Restart policy is also set to Always. 


[email protected]:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[email protected]:/# cd etc
[email protected]:/etc# cd nginx
[email protected]:/etc/nginx# cd conf.d
[email protected]:/etc/nginx/conf.d# ls
default.conf  portainer.conf  webssh.conf  wordpress.conf
[email protected]:/etc/nginx/conf.d# cat wordpress.conf 
server {
    listen       80;
    server_name  opc1www.51sec.org 132.145.9.4 51sec.org;
##    rewrite ^/(.*)$ //ezoic.51sec.org/$1 redirect;

location / {
    proxy_pass       http://132.145.9.4:10000;
    proxy_redirect             off;
    proxy_http_version         1.1;
    proxy_set_header Upgrade   $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
[email protected]:/etc/nginx/conf.d# 



[email protected]:/etc/nginx/conf.d# cat portainer.conf 
server {
    listen       80;
    server_name  opc1portainer.51sec.org;

location / {
    proxy_pass       http://132.145.9.41:9000;
    proxy_redirect             off;
    proxy_http_version         1.1;
    proxy_set_header Upgrade   $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}


[email protected]:/etc/nginx/conf.d# cat webssh.conf 
server {
    listen       80;
    server_name  webssh.51sec.org;

location / {
    proxy_pass       http://132.145.9.41:8080;
    proxy_http_version         1.1;
    proxy_read_timeout 300;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Real-PORT $remote_port;
           }
}
[email protected]:/etc/nginx/conf.d# 


References











No comments