Dockerfile 示例二:创建一个Nginx的镜像
来源:互联网 发布:axure rp pro mac版 编辑:程序博客网 时间:2024/06/05 00:21
Dockerfile 示例二:创建一个Nginx的镜像
Nginx简述
Nginx是一个高性能的 HTTP 和 反向代理 服务器。它因为它的轻量级,易用,易于扩展而流行于业界。基于优良的架构设计,它能够比之前的类似软件处理更多的请求。它也可以用来提供静态文件服务,比如图片,脚本和CSS。
和上个例子一样,我们还是从基础镜像开始,运用FROM命令和MAINTAINER命令
############################################################
# Dockerfile to build Nginx Installed Containers
# Based on Ubuntu
############################################################
# Set the base image to Ubuntu
FROM ubuntu
# File Author / Maintainer
MAINTAINER Maintaner Name
安装Nginx
# Install Nginx
# Add application repository URL to the default sources
RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list
# Update the repository
RUN apt-get update
# Install necessary tools
RUN apt-get install -y nano wget dialog net-tools
# Download and Install Nginx
RUN apt-get install -y nginx
Bootstrapping
安装Nginx后,我们需要配置Nginx并且替换掉默认的配置文件
# Remove the default Nginx configuration file
RUN rm -v /etc/nginx/nginx.conf
# Copy a configuration file from the current directory
ADD nginx.conf /etc/nginx/
# Append "daemon off;" to the beginning of the configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# Expose ports
EXPOSE 80
# Set the default command to execute
# when creating a new container
CMD service nginx start
保存 dockfile。
使用Dockerfile自动构建Nginx容器
因为我们命令Docker用当前目录的Nginx的配置文件替换默认的配置文件,我们要保证这个新的配置文件存在。在Dockerfile存在的目录下,创建nginx.conf:
sudo nano nginx.conf
然后用下述内容替换原有内容:
worker_processes 1;
events { worker_connections 1024; }
http {
sendfile on;
server {
listen 80;
location / {
proxy_pass http://httpstat.us/;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
让我们保存nginx.conf。之后我们就可以用Dockerfile和配置文件来构建镜像。
0 0
- Dockerfile 示例二:创建一个Nginx的镜像
- Dockerfile 示例一:创建一个MongoDB的镜像
- dockerfile创建nginx镜像
- 通过Dockerfile创建nginx服务的Centos镜像
- 【Dockerfile】使用Dockerfile创建带nginx服务的Centos Docker镜像
- 「二」创建一个带 ssh 服务的基础镜像(修订版)--使用 Dockerfile 创建
- Dockerfile创建镜像
- Docker实战:使用Dockerfile创建带nginx服务并支持ssh的Centos Docker镜像
- Dockerfile:nginx镜像编写
- Docker学习记录(二)-Dockerfile创建镜像
- Dockerfile 创建 tomcat 镜像
- dockerfile 创建 ssh 镜像
- Dockerfile 创建简单镜像
- docker创建本地镜像(二)及Dockerfile的语法
- 使用Dockerfile创建一个带 ssh 服务的基础镜像
- 通过Dockerfile创建支持SSH服务的CentOS镜像
- 使用DockerFile创建ubuntu下的tomcat镜像
- 使用Dockerfile创建自己的docker镜像
- 普通LIST列表转换为Tree
- 关于Win7下安装VS2013就崩溃的问题
- UTC时间和Local时间
- selenium+python windows环境搭建
- 【PHP开发】Mac系统配置MAMP+Thinkphp框架环境 教程(一)
- Dockerfile 示例二:创建一个Nginx的镜像
- 基于STM32和RC632的读写器设计(硬件版)
- Spring3.3 整合 Hibernate3、MyBatis3.2 配置多数据源/动态切换数据源 方法
- iSO控制器的生命周期
- jQuery EasyUI使用教程之使用标记创建树形菜单
- 来到CSDN的第一天
- Jsonp解决ajax跨域问题
- 如何在程序中随时的退出程序
- 4.JVM内存模型