Docker使用---静的Webサイトテスト

2296 ワード

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 "[email protected]"
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 .

Webサイトの作成
# 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ファイルはいつでも変更できます
ボリューム
アプリケーションやコードをミラーに構築したくない場合、ボリュームの価値が現れます.
  • コードの開発とテストを同時に行うことを望む
  • コードの変更は頻繁で、開発中にミラー
  • を再構築したくない.
  • は、複数のコンテナ間でコード
  • を共有することを望む.