D
D
di2020-07-03 13:36:56
Nginx
di, 2020-07-03 13:36:56

What are the tools to automate the deployment of applications with Docker and Nginx?

I have a VPS, I installed nginx there. Often you have to raise small web applications and all sorts of bots, these applications are test ones, they are not used commercially anywhere, they don’t have a special load, this server is just for demos. And since their number is growing, I'm thinking about automating the process.

When I want to deploy a bot, for example, my process is like this.
1. Built the image -> pushed it into the registry. For example, in docker.io
2. I launch the image on the server with the necessary environment variables on a specific port

docker run --name=jokebot -d -e VK_ACCESS_TOKEN=<token> -p <deploy_port>:80 delgus/jokebot

For example, I'll choose a free port 5000 and it turns out that the container listens on 127.0.0.1:5000
3. The actual nginx setup. I add a config for a new subdomain (deploy each new application on a new subdomain of my domain)
in sites-available
server {
        listen 80;
        listen 443 ssl http2;
        server_name sub.domain.com;
        ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
        ssl_trusted_certificate /etc/letsencrypt/live/domain.com/chain.pem;

        ssl_stapling on;
        ssl_stapling_verify on;
        resolver 127.0.0.1 8.8.8.8;

        location / {
                proxy_pass http://127.0.0.1:5000;
        }

        location /.well-known {
                  root /var/www/letsencrypt;
        }
}


then I create a symbolic link to sites-enabled and do a service nginx reload,
then I go to redo the cert via letsencrypt bot.

With this method of deployment, problems arise.
1. the same job of creating a subdomain (in theory, you can write a script that will do it yourself, but maybe there is a ready-made solution)
2. I don’t like that you can open an application at my_server_ip:5000 bypassing nginx.
3. when there will be more applications, I will get confused in the ports that I gave to different applications.

So I'm starting to think about some kind of lightweight container orchestration tool, or some more convenient way to organize all this.
Containerized applications are mostly written in golang. I use Nginx just as a proxy.
How bad is my deployment method? are there better options?
My server only has 1 GB of RAM because my applications don't need much, so I don't see the point in some cumbersome things like kubernetes and docker swarm.

What do you advise?

PS. do not swear much, I'm back and not devops

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2020-07-03
@Delgus

You need nginx-proxy , here's one of the coolest ones. https://hub.docker.com/r/jwilder/nginx-proxy/dockerfile
You just specify VIRTUAL_HOST and VIRTUAL_PORT when starting the container and it itself registers where it is needed and just starts to be proxied to the running container.

S
Stanislav Bodrov, 2020-07-05
@jenki

1. Built the image -> pushed it into the registry. For example, in docker.io
2. I run the image on the server with the necessary environment variables on a specific port
3. ....
The usual deployment process from the CI / CD area. You can immediately send the finished image to the target server and run it there as you please. Someone writes a little Ansible policy that does everything.

F
flcae, 2020-07-07
@flcae

Hello, how can I contact you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question