代码改变世界

Docker学习4 --案列

2016-05-08 18:56  Qin奋  阅读(169)  评论(0)    收藏  举报

1. Sample

[root@iZ236vrgbw9Z dockerSpace]# mkdir sample
[root@iZ236vrgbw9Z dockerSpace]# cd sample/
[root@iZ236vrgbw9Z sample]# touch Dockerfile
[root@iZ236vrgbw9Z sample]# mkdir nginx && cd nginx
[root@iZ236vrgbw9Z nginx]# ls
[root@iZ236vrgbw9Z nginx]# wget https://raw.githubusercontent.com/jamtur01/dockerbook-code/master/code/5/sample/nginx/global.conf
--2016-05-08 15:29:07--  https://raw.githubusercontent.com/jamtur01/dockerbook-code/master/code/5/sample/nginx/global.conf
Resolving raw.githubusercontent.com... 185.31.19.133
Connecting to raw.githubusercontent.com|185.31.19.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 286 [text/plain]
Saving to: “global.conf”

100%[====================================================================================================================================================================================================================================>] 286         --.-K/s   in 0s      

2016-05-08 15:31:07 (58.9 MB/s) - “global.conf” saved [286/286]

[root@iZ236vrgbw9Z nginx]# wget https://raw.githubusercontent.com/jamtur01/dockerbook-code/master/code/5/sample/nginx/nginx.conf
--2016-05-08 15:31:43--  https://raw.githubusercontent.com/jamtur01/dockerbook-code/master/code/5/sample/nginx/nginx.conf
Resolving raw.githubusercontent.com... 23.235.43.133
Connecting to raw.githubusercontent.com|23.235.43.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 415 [text/plain]
Saving to: “nginx.conf”

Dockerfile:
FROM ubuntu:14.04
MAINTAINER qinjiayan "qinjiayan@buaa.edu.cn"
ENV REFRESHED_AT 2016-05-08
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

[root@iZ236vrgbw9Z sample]# docker build -t jiayan_prac01/nginx .
Sending build context to Docker daemon 4.608 kB
Sending build context to Docker daemon
Step 0 : FROM ubuntu:14.04
 ---> 41cc538fb83a
Step 1 : MAINTAINER qinjiayan "qinjiayan@buaa.edu.cn"
 ---> Running in 2cf119608fbc
......
Successfully built 492bf103a7d0
[root@iZ236vrgbw9Z sample]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
jiayan_prac01/nginx       latest              492bf103a7d0        11 minutes ago      227.8 MB
nignx_image               latest              04a2fb47e4b8        3 days ago          227.8 MB
coconut_repo/static-web   v1                  af7dfcd4056f        3 days ago          206.1 MB

[root@iZ236vrgbw9Z sample]# mkdir website && cd website
[root@iZ236vrgbw9Z website]# vi index.html

[root@iZ236vrgbw9Z website]# docker run -d -p 80 --name website \-v $PWD/website:/var/www/html/website \jiayan_prac01/nginx nginx
a774c6d91bb9cc73233530c4ee10c87a5b6f7e7c00be66911679a610ae147802

[root@iZ236vrgbw9Z website]# docker ps -a
CONTAINER ID        IMAGE                                                              COMMAND                CREATED             STATUS                        PORTS                   NAMES
a774c6d91bb9        jiayan_prac01/nginx                                                "nginx"                8 seconds ago       Up 8 seconds                  0.0.0.0:32771->80/tcp   website               
df68ae4a4681        ad96d601ddb6121362b5f0724b0078976f0d4327f687034660599c7da55cd267   "/bin/sh -c 'apt-get   47 minutes ago      Exited (100) 36 minutes ago                           hopeful_poitras     

[root@iZ236vrgbw9Z website]# docker ps
CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS                   NAMES
a774c6d91bb9        jiayan_prac01/nginx   "nginx"             21 seconds ago      Up 20 seconds       0.0.0.0:32773->80/tcp   website             
96f0296aee89        41cc538fb83a          "/bin/bash"         5 days ago          Up 4 days                                   hungry_elion      

[root@iZ236vrgbw9Z website]# vi index.html