Quickly deploy docker, nginx and certbot

In our team, we often face the need to deploy new servers with the same configuration: nginx, docker, docker-compose and certbot. We use nginx to proxy Docker and assign human DNS. In order not to repeat ourselves, we have developed a set of scripts that allow you to quickly and easily install and configure these components on servers with the Ubuntu 22 operating system and higher. In this article, we will share these scripts and tell you how they help reduce time and avoid mistakes when creating a new environment.

Scripts

The script repository is available on GitHub: prepare-server. It includes three main scripts:

  1. install_docker.sh – for installing docker.io and docker-compose.

  2. install_nginx.sh — for installing nginx and certbot.

  3. add_proxy.sh — to configure nginx as a proxy for docker containers.

Installing Docker and Docker Compose

Script install_docker.sh installs docker.io and docker-compose, and also adds the current user to the docker group so that you can run docker commands without sudo.

Instructions for use:

  1. Clone the repository:

    git clone https://github.com/CloudLab-Studio/prepare-server.git
    cd prepare-server
  2. Make the script executable:

    chmod +x install_docker.sh
  3. Run the script:

    ./install_docker.sh

Installing Nginx and Certbot

Script install_nginx.sh installs nginx, certbot and configures a firewall to allow http and https traffic.

Instructions for use:

  1. Make the script executable:

    chmod +x install_nginx.sh
  2. Run the script specifying the desired nginx version:

    ./install_nginx.sh [stable|mainline]

Setting up Nginx as a proxy

Script add_proxy.sh configures proxy configuration for nginx and obtains SSL certificate using certbot.

Instructions for use:

  1. Make the script executable:

    chmod +x add_proxy.sh
  2. Run the script and follow the prompts:

    ./add_proxy.sh
  3. You will be prompted to enter:

Instead of a conclusion

  1. Security: The script does not configure security, you need to take care of this yourself. Hosters often issue VDS with all ports open to the outside, and your service will be accessible both by domain name and by port.

  2. Why scripto is only for Ubuntu: I spent many nights studying distributions 20 years ago and the first human distribution that I got was Ubuntu – we live with it for most projects.

  3. If you have similar scripts for quickly raising services on new servers, share and contribute, welcome.

Similar Posts

Leave a Reply

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