[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》的阅读笔记

六翁

目录
相关文章
|
17天前
|
前端开发 应用服务中间件 nginx
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
78 0
|
25天前
|
前端开发 应用服务中间件 nginx
使用Docker快速搭建Web服务器Nginx
本文指导如何使用Docker快速搭建Nginx服务器。首先,通过`docker pull`命令获取Nginx镜像,然后以容器形式运行Nginx并映射端口。通过挂载目录实现本地文件与容器共享,便于自定义网页。使用`docker ps`检查运行状态,访问IP:8088确认部署成功。最后,介绍了停止、删除Nginx容器的命令,强调Docker简化了服务器部署和管理。
39 0
|
2天前
|
应用服务中间件 Linux 开发工具
如何在阿里云服务器快速搭建部署Nginx环境
以下是内容的摘要: 本文档主要介绍了在阿里云上购买和配置服务器的步骤,包括注册阿里云账号、实名认证、选择和购买云服务器、配置安全组、使用Xshell和Xftp进行远程连接和文件传输,以及安装和配置Nginx服务器的过程。在完成这些步骤后,你将能够在服务器上部署和运行自己的网站或应用。
|
6天前
|
弹性计算 应用服务中间件 Linux
阿里云ECS服务器上从零开始搭建nginx服务器
阿里云ECS服务器上从零开始搭建nginx服务器
|
30天前
|
jenkins Java 持续交付
Docker Swarm总结+Jenkins安装配置与集成snarqube和目标服务器(4/5)
Docker Swarm总结+Jenkins安装配置与集成snarqube和目标服务器(4/5)
43 0
|
30天前
|
NoSQL 关系型数据库 MySQL
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
193 0
|
1月前
|
负载均衡 应用服务中间件 nginx
|
1月前
|
弹性计算 算法 应用服务中间件
倚天使用|Nginx性能高27%,性价比1.5倍,基于阿里云倚天ECS的Web server实践
倚天710构建的ECS产品,基于云原生独立物理核、大cache,结合CIPU新架构,倚天ECS在Nginx场景下,具备强大的性能优势。相对典型x86,Http长连接场景性能收益27%,开启gzip压缩时性能收益达到74%。 同时阿里云G8y实例售价比G7实例低23%,是Web Server最佳选择。
|
1月前
|
前端开发 应用服务中间件 nginx
Docker安装nginx和基本配置
Docker安装nginx和基本配置
124 0
|
2月前
|
网络协议 Unix 应用服务中间件
如何进行 Nginx HTTPS服务器搭建
【2月更文挑战第6天】
63 0