欢迎来到无荨的博客

想一千次,不如去做一次。如果自己不努力,那么这一辈子只可能在原地踏步!

项目——基于httpd镜像演示Dockerfile所有的指令


基于httpd镜像演示Dockerfile所有的指令:

第一步:创建Dockerfile工作目录

[root@localhost harbor]# mkdir /test
[root@localhost harbor]# cd /test/
[root@localhost test]# echo 11111 > 1.txt
[root@localhost test]# ls
1.txt 
[root@localhost test]# vim Dockerfile
FROM httpd:latest
LABEL author=wuxun
ENV dir=/usr/local/apache2/htdocs
WORKDIR $dir
COPY 1.txt ./
RUN touch {1..3}.txt
ADD https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/adwaita-qt-common-1.0-1.el7.x86_64.rpm ./
EXPOSE 80 3306
VOLUME $dir
CMD ["httpd-foreground"] 

第二步:基于dockerfile创建镜像

[root@localhost test]# docker build -t httpd:test1
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
[root@localhost test]# docker build -t httpd:test1 ./
Sending build context to Docker daemon 3.072kB
Step 1/10 : FROM httpd:latest
---> fb2f3851a971
...
Successfully built 8b0d23d4e733
Successfully tagged httpd:test1
[root@localhost test]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd test1 8b0d23d4e733 3 minutes ago 178MB

第三步:基于新创建的镜像启动容器

[root@localhost test]# docker run -d httpd:test1
5b6975fd8ad966bd8359ebe0538bd22cb0c9f43d2d6d98c64e806bef93f32e88
[root@localhost test]# docker ps
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS                 PORTS                       NAMES
5b6975fd8ad9        httpd:test1                                         "httpd-foreground"       18 seconds ago      Up 17 seconds          80/tcp, 3306/tcp            jolly_gagarin

第四步:验证  

[root@localhost test]# docker exec -it 5b6975fd8ad9 bash
root@5b6975fd8ad9:/usr/local/apache2/htdocs# ls
1.txt  adwaita-qt-common-1.0-1.el7.x86_64.rpm  index.html  {1..3}.txt
root@5b6975fd8ad9:/usr/local/apache2/htdocs# exit
exit
[root@localhost test]# docker image ls |grep httpd
httpd                           test1                      8b0d23d4e733        31 minutes ago      178MB
192.168.59.200/test/httpd       v1                         fb2f3851a971        18 months ago       178MB
httpd                           latest                     fb2f3851a971        18 months ago       178MB
[root@localhost test]# docker ps | grep httpd
5b6975fd8ad9        httpd:test1                                         "httpd-foreground"       26 minutes ago      Up 26 minutes          80/tcp, 3306/tcp            jolly_gagarin

  

posted @ 2019-11-14 10:11  无荨  阅读(597)  评论(0编辑  收藏  举报