Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How docker nginx deploys multiple projects

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge points about how to deploy multiple projects in docker nginx. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.

prerequisite

1. Docker has been installed on local computers and servers. Google the download method.

2. You already have an account on docker hub and register for the portal:

3. Need to be familiar with docker and understand some instructions in dockerfile

Use dockerfile to make mirrors

If there is a project called web on this machine

Create a new dockerfile under the web root directory and write the following

From nginx:1.13.6-alpinelabel maintainer= "lilywang" arg tz= "asia/shanghai" env tz ${tz} run apk upgrade-- update\ & & apk add bash tzdata\ & & ln-sf / usr/share/zoneinfo/$ {tz} / etc/localtime\ & & echo ${tz} > / etc/timezone\ & & rm-rf / var/cache/apk/*copy dist / usr/share/nginx/html cmd ["nginx", "- g", "daemon off;"]

The file structure in web is as follows:

. | _ dockerfile | _ dist / / the packaged file of the project | | _ index.html

Next, go to the web directory in bash

Cd webdocker build-t lilywang711/web.

If you see the following in the print message, the image has been built successfully.

Successfully built 4c050212ce0d

Successfully tagged lilywang711/web:latest

You can also enter docker images to view the current image list

Next, enter the command docker push lilywang711/web to upload the image you just constructed to docker hub. It is convenient for us to pull the image from the server later.

If there are multiple projects to deploy, just repeat the above steps and build as many images as there are projects.

Server deployment

Ssh login server, under the current user directory (I am root directory), create a new nginx folder, and create a new nginx.conf in it

Write the following in nginx.conf

User nginx;worker_processes 2 error error log / var/log/nginx/error.log warn;pid / var/run/nginx.pid;events {use epoll; worker_connections 2048;} http {include / etc/nginx/mime.types; # include / etc/nginx/conf.d/*.conf; root / usr/share/nginx/html; index index.html index.htm; server {listen 80; server_name a.yourdomain.cn; location / {}} server {listen 80; server_name b.yourdomain.cn Location / {proxy_pass http://your_vps_ip:81;}} server {listen 80; server_name localhost; location / {}

Next

Start docker systemctl start docker

Pull the two images just made and uploaded

Docker pull lilywang711/web

Docker pull lilywang711/web1

Enter the following command to start the container

Docker run-itd-- name web-p 80:80-v / root/nginx/nginx.conf:/etc/nginx/nginx.conf lilywang711/web//-I interactive mode running container,-t assigns a pseudo terminal to the container, and-d background runs the container, which can be directly linked to-itd//-- name gives the container the name web. It is easy to identify that / /-p is the binding port native port 80: container port 80max /-v declares volume, which means to mount the / etc/nginx/nginx.conf in the container to the / root/nginx/nginx.conf in the host. You only need to modify / root/nginx/nginx.conf to configure nginx later.

The same is true for another lilywang711/web1 image. Just change the port and name.

Docker run-itd-- name web1-p 81:80-v / root/nginx/nginx.conf:/etc/nginx/nginx.conf lilywang711/web1

At this point, type docker ps and you can see that the two containers are running.

The docker project and deployment in nginx has been completed.

Enter http://a.yourdomain.cn and http://b.yourdomain.cn in the browser to see the effect, corresponding to the web and web1 projects on the local computer, respectively.

These are all the contents of the article "how to deploy multiple projects in docker nginx". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report