首页 > 系统相关 >Docker 中使用Nginx网站的搭建

Docker 中使用Nginx网站的搭建

时间:2023-02-19 17:34:03浏览次数:51  
标签:container nginx Nginx Docker more docker containers 搭建

Docker 中使用Nginx网站的搭建

使用Nginx 来搭建完整的前置站点,实现后向的代理,这篇文章中简单介绍一个搭建的步骤,至于Nginx 的知识,Docker 的使用可以参考对应的文档。

前提条件

  • Ubuntu (20.04)
  • Docker (23.0.1 Community)
  • Nginx

安装步骤

  • Ubuntu
    • 云服务器,国内的国外的都行,花点钱买一台
  • Docker 安装步骤,参考链接,做个简单的翻译
    • 首先更新系统 sudo apt update
    • 安装一些依赖的软件 sudo apt install apt-transport-https ca-certificates curl software-properties-common
    • 将Docker 官网仓储添加到系统的GPGkey中 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    • 将Docker 仓储添加到APT源中echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    • 更新系统 sudo apt update
    • 再次确认一下,你是从docker仓储中安装而不是ubuntu 中安装apt-cache policy docker-ce
    • 安装Dockersudo apt install docker-ce
    • 检查一下Docker的守护进程是否运行sudo systemctl status docker
  • 介绍几个Docker 中常用的命令
Command Comments
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
  • Nginx 安装步骤 参考链接

    • 拉取docker 源 docker pull nginx
    • 启动nginx docker run --name docker-nginx -p 80:80 nginx
      • 这样我们就启动了一个默认配置下的nginx 服务器,监听端口在80.
  • 下面我们要启动两个不同的网站,他们在同一台服务器下,同一个端口,只是通过不同的域名访问。假设域名为DomainA.com, DomainB.com端口都是80.

    • 首先基于上一步,我们先从docker 中copy 出一个默认的配置文件
      docker cp docker-nginx:/etc/nginx/conf.d/default.conf ~/default.conf
    • 然后修改这个文件,先复制里面的server directive, 然后将里面的server 配置成DomainA.com, 第二个server 配置成DomainB.com
    • 修改里面的root, 加入改成/var/www/SiteA, /var/www/SiteB
    • 在我们的ubuntu 上也新建一个SiteA,SiteB 的目录放入html.
    • 我们通过磁盘挂载的方式来启动nginx,具体参考这个链接
    • 首先我们把上一步的nginx 删除 docker rm docker-nginx
    • 重新启动 docker run --name docker-nginx -p 80:80 -v /local/SiteA:/var/www/SiteA -v /local/default.conf:/etc/nginx/conf.d/default.conf -v /local/SiteB:/var/www/SiteB

    Happy Coding

标签:container,nginx,Nginx,Docker,more,docker,containers,搭建
From: https://www.cnblogs.com/kongshu-612/p/17135146.html

相关文章

  • Linux/VScode搭建Rust开发环境
    1、Linux下搭建Rust开发环境1.1、使用Rustup安装  执行如下命令curl--proto'=https'--tlsv1.2-sSfhttps://sh.rustup.rs|sh  执行结果如下:  在这里使用......
  • Docker
    一、背景二、Docker简介1、定义Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的Linux或Windows操作系......
  • games104 现代游戏引擎 Picoolo环境搭建 vulkan配置
    0前言介绍games104现代游戏引擎课程是由GAMES:GraphicsAndMixedEnvironmentSymposium支持的一个课程。如我们所视,Games并非的含义并不是游戏,而是计算机图形学......
  • ActiveMQ服务搭建
    ActiveMQ服务搭建启动activeMQ服务器1首先要下载bin压缩文件https://activemq.apache.org/Components->ActiveMQ"Classic"->下载apache-activemq-5.9.0-bin.tar......
  • docker push 到私有仓库提示(Client.Timeout exceeded while awaiting headers)
    如果docker在上传镜像的时候出现该问题,那么大概率是私有仓库的docker不通[root@localhostdocker]#dockerpush192.168.223.136:5000/xiaoniao:v1Thepushrefersto......
  • Nginx+Rtmp推流服务器方案
    推流服务器方案一一、前期准备操作系统:Centos7Linux系统Nginx版本:nginx-1.22.0.tar.gzRTMP模块:nginx-rtmp-module推流工具:OBS-Studio拉流工具二、环境搭建1.安......
  • XXL-JOB 分布式任务调度框架(Cron表达式、环境搭建、整合SpringBoot、广播任务与动态分
    (目录)xxl-Job分布式任务调度1.概述1.1什么是任务调度我们可以先思考一下业务场景的解决方案:某电商系统需要在每天上午10点,下午3点,晚上8点发放一批优惠券。某银行......
  • LVS(Linux Virtual Server)+Nginx 高可用集群
    LVS(Linux虚拟服务器)LVS(LinuxVirtualServer)是一个开源的负载均衡项目,是国内最早出现的开源项目之一,目前已被集成到Linux内核模块中。该项目在Linux内核中实现了基于......
  • Nginx location
                                                 c......
  • MongoDB简介与应用场景、Docker安装Mongo、整合SpringBoot实现CRUD
    (目录)1MongoDB相关概念1.1业务应用场景传统的关系型数据库(如MySQL),在数据操作的“三高”需求以及应对Web2.0的网站需求面前,显得力不从心。解释:“三高”需求:•Hi......