1. 程式人生 > >docker筆記之dockerfile

docker筆記之dockerfile

from --構建的新映象是基於哪個映象的

Build映象命令

 [[email protected] ~]# docker build --help
 
 Usage:	docker build [OPTIONS] PATH | URL | -
 
 Build an image from a Dockerfile
 
 [OPTIONS] 
 -t  --tag list  #映象名稱
 -f  --file string  # 指定Dockerfile檔案位置

示例:

 docker build .  #預設找當前目錄以Dockerfile命名的檔案

dockerfile構建PHP網站環境映象

 [[email protected] ~]# cat Dockerfile 
 FROM centos:6
 MAINTAINER jinc
 RUN yum install -y httpd php php-gd php-mysql mysql mysql-server
 ENV MYSQL_ROOT_PASSWORD 123456
 RUN echo "<?php phpinfo()?>" > /var/www/html/index.php
 
 ADD start.sh /start.sh
 RUN chmod +x /start.sh
 
 ADD http://cn.wordpress.org/wordpress-4.7.4-zh_CN.tar.gz /var/www/html
 #COPY wp-config.php /var/www/html/wordpress
 
 VOLUME ["/var/lib/mysql"]
 
 CMD /start.sh
 
 EXPOSE 80 3306

建立映象

 [[email protected] ~]# docker build -t wordpress:v1 .
 Sending build context to Docker daemon  4.437MB
 Step 1/11 : FROM centos:6
 。。。
 Step 11/11 : EXPOSE 80 3306
  ---> Running in a5eb6330210b
 Removing intermediate container a5eb6330210b
  ---> 67605dda8a82
 Successfully built 67605dda8a82
 Successfully tagged wordpress:v1

檢視

 [[email protected] ~]# docker images
 REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
 wordpress                 v1                  67605dda8a82        2 minutes ago       386MB

使用

 [roo[email protected] ~]# docker run -itd --name wordpress -p 88:80 wordpress:v1
 e25d20fcd627e1193003b7bcce6cfbf3cdae631b02b34024d09cab18054c3b9b
 
 [[email protected] ~]# docker ps
 CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                          NAMES
 f922463ea5db        wordpress:v1        "/bin/sh -c /start.sh"   4 seconds ago       Up 3 seconds        3306/tcp, 0.0.0.0:88->80/tcp   wordpress
 
 通過瀏覽器訪問
 http://10.0.0.205:88/  出現phpinfo 介面
 
 後面就又是WordPress安裝過程了。。就不再說了