How to apply for an Azure subscription and enable a free VPS using Edu Email
Using Edu mailbox not only allows you to apply for a free Azure subscription to enable VPS, but also allows you to use software such as Adobe and Notion for free, greatly improving your learning and work efficiency. If you do not have an Edu email address, you can refer to the online notes/notes-image/edu%E7%AC%94%E8%AE% for relevant information and application methods.
Create a new Ubuntu VPS and deploy a pSQL server through Docker
After you have an Azure subscription, you can follow these steps to create a new Ubuntu VPS in it and deploy a pSQL server through Docker on that VPS. The following is a detailed tutorial:
1. Introduction to Docker and pSQL
Dockeris an open source application container engine that allows developers to package applications and their dependencies into a lightweight container that can run in any environment. It uses operating system-level virtualization to deliver software.
PostgreSQL (pSQL)It is a powerful open source object relational database system, known for its high performance and stability, and is often used in complex applications.
2. Deploy a pSQL server through Docker on Ubuntu
Step 1: Update the system
First, make sure your system is up to date. Update Ubuntu system package:
sudo apt-get update sudo apt-get upgrade
Step 2: Install Docker
Installing Docker is a key step in deploying a pSQL server. Execute the following command to install Docker:
sudo apt-get install -y
Start Docker and set it to boot automatically:
sudo systemctl start docker sudo systemctl enable docker
Verify that Docker is installed successfully:
docker --version
Step 3: Pull PostgreSQL Image
Pull the latest PostgreSQL image from Docker Hub:
docker pull postgres
Step 4: Run the PostgreSQL container
Create and run the PostgreSQL container. In this step, we set the database name, username, and password:
docker run --name my_postgres -e POSTGRES_DB=mydb -e POSTGRES_USER=myuser -e POSTGRES_PASSWORD=mypassword -p 5432:5432 -d postgres
Parameter explanation of the above command:
-
--name my_postgres
: Specify the container name asmy_postgres
。 -
-e POSTGRES_DB=mydb
: Set the database name tomydb
。 -
-e POSTGRES_USER=myuser
: Set the database username asmyuser
。 -
-e POSTGRES_PASSWORD=mypassword
: Set the database password tomypassword
。 -
-p 5432:5432
: Map the host's port 5432 to the container's port 5432. -
-d
: Run containers in the background.
Step 5: Verify PostgreSQL Server
Confirm that the PostgreSQL server is running normally. Enter the PostgreSQL container:
docker exec -it my_postgres bash
Use in containerpsql
Command to connect to the database:
psql -U myuser -d mydb
After a successful connection, you can execute SQL queries to verify the functionality of the database. For example, create a table and insert data:
CREATE TABLE test (id SERIAL PRIMARY KEY, name VARCHAR(50)); INSERT INTO test (name) VALUES ('DockerTest'); SELECT * FROM test;
Through the above steps, you have successfully deployed a PostgreSQL server through Docker on your Ubuntu VPS. This database can now be configured and used as needed.
The above is a detailed tutorial on deploying a pSQL server through Docker. Hope this article helps you and makes your development work more efficient.
This is the end of this article about Docker deploying pSQL servers. For more related content on Docker deploying pSQL servers, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!