[Docker系列·2] 搭建基于Docker的Nginx服务器

简介: ####docker命令别名 **~/.bashrc** ``` # .bashrc alias d="sudo docker” ``` ####docker的nginx工作目录 /home/erichan/d/nginx ####docker的Dockerfile # Version: 0.0.1 FROM feuyeux/ssd MAINTAINE

docker命令别名

~/.bashrc

# .bashrc

alias d="sudo docker”

docker的nginx工作目录

/home/erichan/d/nginx

docker的Dockerfile

# Version: 0.0.1
FROM feuyeux/ssd
MAINTAINER Eric Han "feuyeux@gmail.com"
RUN apt-get update
RUN apt-get -yq install nginx
RUN mkdir -p /var/www/html
ADD nginx/global.conf /etc/nginx/conf.d/
ADD nginx/nginx.conf /etc/nginx/nginx.conf
EXPOSE 80

nginx配置文件

nginx/global.conf

[erichan@localhost nginx]$ cat nginx/global.conf

server {
        listen          0.0.0.0:80;
    server_name     _;
    root            /var/www/html/website;
    index           index.html index.htm;
    access_log /var/log/nginx/default_access.log;
    error_log /var/log/nginx/default_error.log;
}

nginx/nginx.conf

[erichan@localhost nginx]$ cat nginx/nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
events { }
http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
  gzip on;
  gzip_disable "msie6";
  include /etc/nginx/conf.d/*.conf;
}

测试页面

[erichan@localhost nginx]$ cat website/index.html
    <head>
      <title>Test website</title>
    </head>
    <body>
      <h1>This is a test website</h1>
      <p>learning The docker book.</p>
    </body>

启动nginx服务器

d run -d -p 80 --name website -v /home/erichan/d/nginx/website:/var/www/html/website feuyeux/nginx:1.0 nginx

查看nginx进程

d ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                           NAMES
b92b30ce55b6        feuyeux/nginx:1.0   nginx               4 minutes ago       Up 4 minutes        22/tcp, 0.0.0.0:49153->80/tcp   website    

测试Nginx

[erichan@localhost nginx]$ curl http://localhost:49153
<head>
<title>Test website</title>
</head>
<body>
<h1>This is a test website</h1>    
</body>

修改本地文件

[erichan@localhost nginx]$ nano /home/erichan/d/nginx/website/index.html 
[erichan@localhost nginx]$ cat /home/erichan/d/nginx/website/index.html 
<head>
  <title>Test website</title>
</head>
<body>
  <h1>This is a test website</h1>
  <p>I'm learning The docker book.</p>
</body>

测试Docker·Nginx

[erichan@localhost nginx]$ curl http://localhost:49153
<head>
  <title>Test website</title>
</head>
<body>
  <h1>This is a test website</h1>
  <p>I'm learning The docker book.</p>
</body>

停止进程并删除容器

d kill $(d ps -q) && d rm $(d ps -a -q)

本文是《The Docker Book》的阅读笔记

六翁

目录
相关文章
|
3月前
|
缓存 负载均衡 JavaScript
Nginx:高性能Web服务器与反向代理利器
Nginx:高性能Web服务器与反向代理利器
279 110
|
3月前
|
缓存 负载均衡 前端开发
Nginx:高性能的Web服务器与反向代理利器
Nginx:高性能的Web服务器与反向代理利器
251 99
|
3月前
|
缓存 负载均衡 前端开发
Nginx:高性能Web服务器的核心引擎
Nginx:高性能Web服务器的核心引擎
162 47
|
2月前
|
Ubuntu 安全 应用服务中间件
详细指南:配置Nginx服务器在Ubuntu平台上
以上步骤涵盖了基本流程:从软件包管理器获取 Ngnix, 设置系统服务, 调整UFW规则, 创建并激活服务器块(也称作虚拟主机), 并进行了初步优化与加固措施。这些操作都是建立在命令行界面上,并假设用户具有必要权限(通常是root用户)来执行这些命令。每个操作都有其特定原因:例如,设置开机启动确保了即使重启后也能自动运行 Ngnix;而编辑server block则定义了如何处理进入特定域名请求等等。
257 18
|
2月前
|
Ubuntu 安全 应用服务中间件
详细指南:配置Nginx服务器在Ubuntu平台上
以上步骤涵盖了基本流程:从软件包管理器获取 Ngnix, 设置系统服务, 调整UFW规则, 创建并激活服务器块(也称作虚拟主机), 并进行了初步优化与加固措施。这些操作都是建立在命令行界面上,并假设用户具有必要权限(通常是root用户)来执行这些命令。每个操作都有其特定原因:例如,设置开机启动确保了即使重启后也能自动运行 Ngnix;而编辑server block则定义了如何处理进入特定域名请求等等。
319 17
|
10月前
|
前端开发 应用服务中间件 nginx
docker安装nginx,前端项目运行
通过上述步骤,你可以轻松地在Docker中部署Nginx并运行前端项目。这种方法不仅简化了部署流程,还确保了环境的一致性,提高了开发和运维的效率。确保按步骤操作,并根据项目的具体需求进行相应的配置调整。
926 25
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
应用服务中间件 Linux nginx
Linux虚拟机磁盘扩容、Docker容器磁盘满的问题、Docker安装nginx
这篇文章讨论了Linux虚拟机磁盘扩容的方法,包括外部配置、具体扩容步骤和扩容后的效果验证。同时,文章还涉及了Docker容器磁盘满的问题及其解决方法,如删除不必要的镜像和容器,以及调整Docker的安装路径。此外,还提到了意外情况的处理,例如误删除停止的容器后的应对措施。最后,文章还提供了使用Docker安装nginx的步骤和成功访问的截图。
Linux虚拟机磁盘扩容、Docker容器磁盘满的问题、Docker安装nginx
|
应用服务中间件 nginx Docker
Docker 安装 Nginx
Docker 安装 Nginx
243 0
|
应用服务中间件 Shell nginx
mac m1笔记本docker 安装nginx
mac m1笔记本docker 安装nginx
532 4
下一篇
oss云网关配置