How to run Nginx and MySQL on VPS in 10 minutes
Imagine that you have a box in which you have put everything you need for the application to work: libraries, files, settings. Move the box anywhere - to a PC, a server, or a VPS - and the application works everywhere.
Docker is such a box. In this article, we will tell you how to use it.
The code in the article illustrates working with Docker on a VPS. We show the basic steps and commands so that the reader can understand the principle of operation. However, the actual installation and configuration of Docker differs depending on the operating system configuration, Docker version and VPS peculiarities.
Running Nginx and MySQL on VPS
Configuring Nginx server and MySQL database on a VPS manually will take hours. Docker does it in minutes. Instead of deploying everything separately, you run them from a ready-made container.
Let's see how to deploy Nginx and MySQL on VPS with Docker in 10 minutes.
Step One: Installing Docker on a VPS
Enter all commands through the terminal on the VPS server. First, update the system packages:
sudo apt update && sudo apt upgrade -y
Install Docker using the official repositories:
sudo apt install docker.io -y
Check the installation:
docker --version
Step Two: Starting Nginx in a container
Execute the command:
docker run -d -p 80:80 nginx
Open the IP address of the VPS in your browser. You will see the standard Nginx welcome page.
Step Three: Running MySQL in a container
Start the container with MySQL, specifying the password for the root user:
docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=yourpassword mysql
Connect to the database using any client, such as MySQL Workbench or command line, using the IP of your VPS and port 3306.
Now you have both Nginx and MySQL database running. They are ready to go.
Post a diagram showing a VPS with two containers (Nginx and MySQL), with ports 80 and 3306 signed, and the paths to connect to them via browser and database client.
Why Docker is the ideal tool for Nginx and MySQL on VPS
When traffic to a site grows, you need to add more server capacity. Without Docker, this requires creating new virtual machines or servers, installing Nginx and MySQL on them, configuring and testing. This is time, resources and a high risk of errors.
With Docker, scaling is all about running additional containers. For example, to handle more requests, you simply run multiple Nginx instances and configure load balancing. To do this, you can use Docker Compose to create a configuration for all the containers and services you need:
version: '3'
services:
nginx:
image: nginx
deploy:
replicas: 3
ports:
- "80:80"
Nginx will now run in three instances, distributing the load between them.
Automatic container recovery
When a container fails, Docker automatically replaces it with a new instance. This ensures that your application runs smoothly.
For example, if one of the Nginx containers stops responding, Docker will automatically restart it. This does not require the intervention of a system administrator and helps avoid long downtime.
To enable automatic recovery, just add a command to Docker Compose:
restart: always
Now, if the container goes down, Docker will restart it.
Ease of condition management
With Docker, it is easy to maintain the right configuration and versions of applications. For example, you may have two environments: a test environment and a production environment. With Docker Compose, you can create two different sets of configurations for each environment, for example, with different MySQL versions or Nginx settings.
You simply change the parameters in docker-compose.yml and the containers adjust to the new requirements. This minimizes errors when migrating configurations to another server.
version: '3'
services:
nginx:
image: nginx:latest
environment:
- NGINX_ENV=production
Docker is not just a development tool. With it, you'll increase or decrease the number of containers, ensuring that your application can handle any number of requests. Automatic recovery, easy state management, and orchestration support make Docker the ideal solution for anyone running a VPS who needs high availability and scalability.
Docker simplifies resource management on your VPS. It allows you to efficiently use available resources, control load, optimize performance and save money on hardware. Virtualization in containers is not only about savings, but also about ease of management, monitoring and scaling.
Why VPS from LikeVPS are ideal for running Docker containers
If you want to use Docker, renting a VPS from LikeVPS is a simple and cost-effective solution. Here's why:
- Choose the resources you need. With a VPS from LikeVPS, you can customize your server the way you need it. For example, if your Docker container needs more memory or a more powerful CPU, you can easily change that.
- Runs fast. A VPS from LikeVPS is a full-fledged server that runs faster and more stable than regular hosting. This is important so that your containers don't hang or slow down.
- Easy to set up. The LikeVPS platform is easy to use. You can set up a server for Docker in a few minutes without any hassle.
- Price and quality. The tariffs for VPS from LikeVPS are quite affordable. Even on the minimum tariff you will get everything you need to work with Docker without overpaying.
- Instant start. Rent a server and start working in a couple of minutes. No long customizations - everything is ready to use.
VPS rental from LikeVPS is a profitable and convenient solution for everyone who plans to work with Docker. Start right now and create isolated containers for your applications without extra time and effort.