Info Security Memo
  • Blog
  • Sitemap
    • Categories
  • Contact
  • About
  • Resources
  • Tools
  • 51sec.org

Build Confidence

Focusing on Information Security 

Info Security Notes

Using My Own Docker Images to Create Wordpress Site in Portainer

11/22/2020

0 Comments

 
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.


root@50fe35df8efd:/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
root@50fe35df8efd:/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.

root@4d9db0cf911b:/# 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. 


root@5fbe841d1f40:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@5fbe841d1f40:/# cd etc
root@5fbe841d1f40:/etc# cd nginx
root@5fbe841d1f40:/etc/nginx# cd conf.d
root@5fbe841d1f40:/etc/nginx/conf.d# ls
default.conf  portainer.conf  webssh.conf  wordpress.conf
root@5fbe841d1f40:/etc/nginx/conf.d# cat wordpress.conf 
server {
    listen       80;
    server_name  opc1www.51sec.org 132.145.9.4 51sec.org;
##    rewrite ^/(.*)$ http://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;
    }
}
root@5fbe841d1f40:/etc/nginx/conf.d# 



root@5fbe841d1f40:/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;
    }
}


root@5fbe841d1f40:/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;
           }
}
root@5fbe841d1f40:/etc/nginx/conf.d# 


References

  • Install Portainer to Manage Containers - Nginx, MySQL, WordPress












via Blogger https://ift.tt/3nPMa2K
November 22, 2020 at 04:53PM Blog, Docker
0 Comments



Leave a Reply.

    Categories

    All
    Architecture
    Blog
    Checkpoint
    Cisco
    Cloud
    CyberArk
    F5
    Fortigate
    Guardium
    Juniper
    Linux
    Network
    Others
    Palo Alto
    Qualys
    Raspberry Pi
    Security
    SIEM
    Software
    Vmware
    VPN
    Wireless

    Archives

    March 2024
    February 2024
    January 2024
    December 2023
    November 2023
    October 2023
    September 2023
    August 2023
    July 2023
    June 2023
    May 2023
    April 2023
    March 2023
    February 2023
    January 2023
    December 2022
    November 2022
    October 2022
    September 2022
    August 2022
    July 2022
    June 2022
    May 2022
    April 2022
    March 2022
    February 2022
    January 2022
    December 2021
    November 2021
    October 2021
    September 2021
    August 2021
    July 2021
    June 2021
    May 2021
    April 2021
    March 2021
    February 2021
    January 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    July 2020
    October 2019
    September 2019
    June 2019
    July 2018
    May 2018
    December 2017
    August 2017
    April 2017
    March 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015
    September 2015
    August 2015
    July 2015
    June 2015
    May 2015
    April 2015
    March 2015

    Print Page:

    RSS Feed

    Email Subscribe
Powered by Create your own unique website with customizable templates.
  • Blog
  • Sitemap
    • Categories
  • Contact
  • About
  • Resources
  • Tools
  • 51sec.org