Docker使用---静态网站测试
2016-07-10 16:10
661 查看
Dockerfile
#为Nginx Dockerfile创建一个目录 $ mkdir sample $ cd sample $ touch Dockerfile #获取Nginx配置文件 $ cd sample $ mkdir nginx && cd nginx $ wget https://raw.githubusercontent.com/jamtur01/dockerbook-code/master/code/5/sample/nginx/global.conf $ wget https://raw.githubusercontent.com/jamtur01/dockerbook-code/master/code/5/sample/nginx/nginx.conf $ cd .. FROM ubuntu:14.04 MAINTAINER juedaiyuer "juedaiyuer@gmail.com" ENV REFRESHED_AT 2016-7-10 RUN apt-get update RUN apt-get -y -q 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 #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.conf #阻止nginx进入后台,强制其在前台运行;保持Docker容器的活跃状态,其中运行的进程不能中断 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; } #构建镜像 $ sudo docker build -t juedaiyuer/nginx .
创建网站
#在sample目录下的操作 $ mkdir website && cd website $ wget https://github.com/jamtur01/dockerbook-code/blob/master/code/5/sample/website/index.html $ cd .. # -v 允许我们将宿主机的目录作为卷,挂载到容器里 $ sudo docker run -d -p 80 --name website -v $PWD/website:/var/www/html/website juedaiyuer/nginx nginx $ sudo docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b46432754bc4 juedaiyuer/nginx "nginx" 19 seconds ago Up 18 seconds 0.0.0.0:32768->80/tcp website http://localhost:32768
可以随时对index文件进行修改
卷
不想把应用或者代码构建到镜像中时,卷的价值得到体现希望同时对代码做开发和测试
代码改动很频繁,不想在开发过程中重构镜像
希望在多个容器间共享代码
相关文章推荐
- 轻松搭建docker应用的mesos集群
- Docker distrubution in django
- docker的一些常用命令整理
- web项目docker化的两种方法
- Docker镜像和仓库笔记
- Docker中部署Kubernetes
- Docker学习笔记2
- docker的php容器安装 memcached
- 非常详细的 Docker 学习笔记
- Docker 1.12.0将要发布的新功能
- 使用Docker实现丝般顺滑的持续集成
- docker源代码编译
- Docker - WARNING: No memory limit support 问题解决
- CentOS7安装Docker,运行Nginx镜像、Centos镜像
- 使用Docker实现持续集成
- 运维-makefile的书写(节省dockerFile的批量构建的问题)
- 运维-Dockerfile的书写
- docker --help
- OpenvSzwitch实现Docker跨主机通信
- Docker安装完成测试