Centos 7 install Docker, Nginx, Reverse proxy, Let’s encrypt certificate manager and Docker web-based management Portainer

There is no secret, that these day's many applications are running on Docker since Docker is flexible and also easy to scale. We know, that there are many options, that come with Docker, for example, Docker Kubernetes and Docker Swarm, and many companies are starting to develop systems, system architecture, and even apps on Docker-based environments. But some companies use Docker for testing apps before deploying them to a production server. Also, large Linux distributors like Centos are creating a specific Docker-based system, which is a license based one and is getting where large popularity in terms of large industries.

But today we will create a manual on how to install Docker, create our first 3 containers.
1. Docker web-based management system known as portainer;
2. Docker Nginx reverse proxy, that forwards incoming traffic to port 80 and 443 to correct container in our tutorial we will be creating a Docker-based environment for some web-based applications;

For this, we recommend using our VPS SSD Hosting since they are suitable for Docker use and flexible. For more info click here

For this tutorial, we are using a Centos 7.

With that, all said let's start.

1 Update Linux packages, by typing the command bellow in your Linux terminal and clicking enter:

yum -y update ; yum -y upgrade ;

2. Let's disable the Centos 7 Default firewall or as we know Firewalld:

systemctl stop firewalld ; systemctl disable firewalld ; systemctl mask --now firewalld ;

3. This is not important, but I like when the UTF-8 is supported so let's enable it:

localectl set-locale LC_CTYPE=en_US.utf8

4. Let's install the required packages for our server so that we can install Docker:

yum install -y yum-utils device-mapper-persistent-data lvm2

5. Let's add Docker installation repository so that our Linux knows from where to download the Docker installation:

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

6. Now let's install Docker-CE:

yum install -y docker-ce

7. Let's add the user to the docker group with the following command.

usermod -aG docker $(whoami)

8. Let's enable Docker to start on system boot and also let's start it:

systemctl enable docker.service ; systemctl start docker.service ;

9. Install Extra Packages for Enterprise Linux;

yum install -y epel-release

Now for some Docker environments, we would need to use docker-compose, so better we should also install it.

10. Let's upgrade Python to the latest version since it will be needed

yum -y upgrade python*

11. For that, we would need to install pip (Python-based )

yum install -y python-pip

12. Now let's upgrade pip to the latest version since by default it doesn't install the latest:

pip install --upgrade pip

13. Let's install Docker composer:

pip install docker-compose

Now when all is set up, the only part for us is to set up Portainer, Nginx reverse proxy and Nginx Let's encrypt for SSL.

14. #Let's pull Nginx-proxy (This will act as a reverse proxy for our Docker environment and will allow multiple websites with ports 80 and 443.

docker pull jwilder/nginx-proxy:latest

Now In our example all Docker containers and some important things to be mapped to the server so that I can create a proper backup and make changes outside the container if I need them, but it is up to you how you would like to play. But in this example, I'm creating as it is easy for everyone.

15. Let's create a directory inside /srv

mkdir /srv/docker

16. Let's start Nginx-proxy

docker run --detach --name nginx-proxy --publish 80:80 --publish 443:443 --volume /srv/docker/certs:/etc/nginx/certs --volume /srv/docker/vhosts.d/:/etc/nginx/vhost.d --volume /srv/docker/vhosts.d/:/usr/share/nginx/html --volume /srv/docker/dhparam:/etc/nginx/dhparam --volume /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

17. Let's pull Nginx-Let's encrypt for managing and validating SSL certificates:

docker pull jrcs/letsencrypt-nginx-proxy-companion:latest

18. Let's start Let's encrypt Nginx-proxy:

docker run --detach --name nginx-proxy-letsencrypt --volumes-from nginx-proxy --volume /var/run/docker.sock:/var/run/docker.sock:ro --env "DEFAULT_EMAIL=your-email@YOURDOMAIN.COM" jrcs/letsencrypt-nginx-proxy-companion

And now for the last part as promised web-based Docker management system called portainer.

19. Let's pull Portainer:

docker pull portainer/portainer

20. Let's start the portainer container:

docker run -d --name portainer-manager -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer

And we are all done, now you can go to http://your-ip_or-domain:9000 and create a user account. For detailed Portainer click here

If you want all the above to be done automatically Just do like so:
Open your Linux terminal and paste this command:

yum -y install git ; git clone http://www.amberit.in/linux-scripts/centos7-docker-portainer-nginx-lets-encrypt.git /srv/ ; chmod +x /srv/amberit.sh ; /srv/amberit.sh ; rm -rf /srv/amberit.sh


Warning: file_get_contents(http://api.wipmania.com/[YOUR SITE URL]): failed to open stream: Connection refused in /var/www/vhosts/amberit.eu/httpdocs/wp-content/themes/amberit/inc/layout-functions.php on line 821