Docker create and push image

  1. create a dockerhub account and create repository
    here I call it “backend-server”
sudo docker run -it -d debian --name backend-server /bin/bash 
### setup the container ####
### sudo docker commit <containerID> <dockerhub repository>[:tag]
sudo docker commit backend-server tbjc1magic/backend-server

sudo docker login docker.io
### enter your dockerhub name and passwd ###

sudo docker push tbjc1magic/backend-server


setup https for wordpress with docker

1. install docker-ce

https://docs.docker.com/install/linux/docker-ce/debian/

2. install docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

3. setup domain name, and link it to the node you are setting up your web server; install letsencrypt on the webserver

git clone https://github.com/certbot/certbot.git
cd certbot
sudo -H ./letsencrypt-auto certonly --standalone -d jianping-lai.com -d www.jianping-lai.com --email tbjc1magic@gmail.com
https://www.linode.com/docs/security/ssl/install-lets-encrypt-to-create-ssl-certificates/

4. install wordpress using docker with the docker-compose.yml below
https://docs.docker.com/compose/wordpress/; and do “sudo docker-compose up -d”

version: '3.3'

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

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "80:80"
       - "443:443"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

5. after start the wordpress docker container,

mkdir -p blog/etc sudo docker cp wordpress_wordpress_1:/etc/apache2 ~/blog/etc/

6. login to the wordpress docker container and do following

a2enmod ssl
service apache2 restart

7. shutdown the container and put the letsencrypt key and certificate combo to the ~/blog/etc/apache2 folder

cd ~/blog/etc/apache2/sites-enabled
sudo cp /etc/letsencrypt/live/jianping-lai.com/*.pem .
sudo ln -s ../sites-available/default-ssl.conf .
# modify the following two lines of default-ssl.conf
SSLCertificateFile      /etc/apache2/sites-enable/fullchain.pem
SSLCertificateKeyFile /etc/apache2/sites-enabled/privkey.pem
cd ~/blog/etc/apache2/mods-enabled
sudo ln -s ../mods-available/socache_shmcb.load .

8. modify the docker-compose.yml file add the following two lines

volumes:
    - /home/tbjc1magic/blog/etc/apache2:/etc/apache2

9. start docker containers again and turn on the ssl redirect plugin

sudo docker-compose up -d