Install and configure Docker on VPS

Docker is an application that makes it simple and easy to run application processes in a container

Using Docker we can host / run different website / application in same VPS. So we can run different wordpress /joomla /any other platforms in a  single VPS using MySQL databases and apache server.

We all know WordPress installations will share an Apache installation and share a MySQL database. That means that if one crashes, it could bring down the other. And if the database gets corrupted, both your sites could be affected.

When we use Docker if one application or website crashed never effect another one .Improve VPS security and stability run perfectively

Here we can check how to install Docker

#1. Installing Docker

Ubuntu

First, run this series of commands using terminal, to set up the Docker repository.

$ sudo apt-get install apt-transport-https ca-certificates curl
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update

Once installed, you can install the latest version of Docker CE.

$ sudo apt-get install docker-ce

 

 

Debian 8

$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
$ sudo apt-get update

Finally, you can install Docker CE.

$ sudo apt-get install docker-ce

 

 

 

Debian 7


$ sudo apt-get install apt-transport-https ca-certificates curl python-software-properties
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
$ sudo apt-get update

You’ll need to edit /etc/apt/sources.list to comment out the following line:

deb-src [arch=amd64] https://download.docker.com/linux/debian wheezy stable

Save and exit the file, and then you can install Docker CE.

$ sudo apt-get install docker-ce

 

 

 

CentOS

Start by enabling the Docker CE repository.

$ sudo yum install yum-utils
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ sudo yum makecache fast

Then, you can install and enable Docker.

$ sudo yum install docker-ce
$ sudo systemctl start docker

 

 

#2. Testing Docker

$ sudo docker run hello-world

#3.Enable Automatic Start Docker

$ sudo systemctl enable docker

 

Docker could be a fantastic tool to assist in your preparation automation and positive has it’s place in testing. however in apply it’s a security nightmare for your live production systems. the matter is that the extra quality created once attempting to securedocker mistreatment the on top of tips outweighs its advantages. It’s foolish to suppose that you just get actual separation mistreatment containers on high of a shared kernel.

 

 Host Multiple Websites withDocker and Nginx

create a Docker network that we will use to bridge all of these containers together

$ docker network create nginx-proxy

then Installing nginx-proxy with Docker

$ docker run -d -p 80:80 --name nginx-proxy --net nginx-proxy -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy

Installing nginx-proxy with docker-compose, create a docker-compose.yml add following commands

version: "3"
services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

networks:
  default:
    external:
      name: nginx-proxy

To run just run following command

$ docker-compose up -d

Also important to note is the –net nginx-proxy line in the Docker command, and the networks: default: external: name: nginx-proxy block in the docker-compose.yml file. These establish that all containers will communicate over that Docker network.

Add a container to the proxy, we can use wordpress as a example

$ docker run -d --name blog --expose 80 --net nginx-proxy -e VIRTUAL_HOST=blog.domain.com wordpress

then copy following code to docker-compose.yml

version: "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
     container_name: wp_test_db

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     expose:
       - 80
     restart: always
     environment:
       VIRTUAL_HOST: blog.domain.com
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
     container_name: wp_test
volumes:
    db_data:

networks:
  default:
    external:
      name: nginx-proxy

double check DNS setup is okey, then it will work smoothly

 

We believe that this article has helped you with the information on Docker and Nginx to Host Multiple Websites. If you have any doubt regarding this topic, please make sure to comment, the professional techies at  Alts solution are always happy to help you. Alts solution is one of the top most Digital marketing and App Development company. We offer high-quality service in Web Design and development, SEO, Web Hosting, App Development and Social Media Marketing,Online Reputation Management. We are one of the top Online Reputation Management in India.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top