SoFunction
Updated on 2025-04-08

Detailed explanation of the steps to deploy NGINX server through Docker under Ubuntu

Today I will bring you a technical sharing. We will use Sanfeng Cloud's free server, configured as 1 core/1G memory/5M bandwidth, to deploy NGINX server through Docker. Although the configuration is not top-notch, it is already very good for experimentation and learning.

Introduction to Docker and NGINX

DockerIt is an open source containerized platform that allows developers to package applications and their dependencies to form standardized containers. It greatly improves the portability and manageability of applications. andNGINXIt is a high-performance HTTP and reverse proxy server. With its lightweight and high concurrency processing capabilities, it is widely used in load balancing and reverse proxy for websites and applications.

Deploy NGINX server through Docker under Alpine Linux

Next, we will explain in detail how to deploy NGINX server through Docker under Alpine Linux. The following are the steps and the corresponding commands.

Step 1: Install Docker

If you haven't installed Docker, you can use the following command to install it:

# Update package indexapk update
# Install Dockerapk add docker

Step 2: Start Docker service

After the installation is complete, start the Docker service:

# Start Docker serviceservice docker start

Step 3: Pull the NGINX image

Use the Docker command to pull the official NGINX image:

# Pull NGINX imagedocker pull nginx

Step 4: Create an NGINX configuration file

Create a configuration file on your host, the content is as follows:

server {
    listen 80;
    server_name localhost;
    location / {
        root   /usr/share/nginx/html;
        index   ;
    }
}

Step 5: Create a Docker container

Now create and run the NGINX container using the following command:

docker run --name mynginx -v /path/to/your/:/etc/nginx/ -p 80:80 -d nginx
  • --name mynginx: Assign a name to the container.
  • -v /path/to/your/:/etc/nginx/: Mount the local configuration file into the container.
  • -p 80:80: Map port 80 of the host to port 80 of the container.
  • -d: Run containers in background mode.

Step 6: Verify the deployment

Finally, open the browser and access your server IP address. If everything is fine, you should be able to see the NGINX welcome page.

So, that’s all for today’s sharing. I hope everyone can gain something while using Docker and NGINX! If you have any questions, please feel free to communicate.

This is the end of this article about deploying NGINX servers through Docker under Ubuntu. For more related content on Docker deployment NGINX servers, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!