创建一个自己的centos
1.编写dockerfile的文件
[root@localhost dockerfile]# cat mydockerfile
FROM centos
MAINTAINER gaole<490135586@qq.com>
ENV MYPATH /usr/local
WORKDIR $MYPATH #一开始的时候这里写错了,没有写$,所有进去以后到了/MYPATH的路径
RUN yum -y install vim
RUN yum -y install net-tools
EXPOSE 80
CMD echo "welcome to gaole's centos"
CMD /bin/bash
2.通过这个文件构建镜像,最后有一个点
[root@localhost dockerfile]# docker build -f mydockerfile -t mycentos:1.0 .
[root@localhost dockerfile]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mycentos 1.0 09170a90d5db 15 seconds ago 326MB
kuangshen/centos latest 915412bdf8be 19 hours ago 231MB
mysql latest 3218b38490ce 5 weeks ago 516MB
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos latest 5d0da3dc9764 4 months ago 231MB
3.运行测试
docker run -it mycentos:1.0 #直接就进去了,然后就会到工作目录,注意必须要加版本号,不加默认下载最新版本
4.docker history +imagesID 可以看到镜像构建的过程
[root@localhost dockerfile]# docker history 09170a90d5db
IMAGE CREATED CREATED BY SIZE COMMENT
09170a90d5db 7 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "/bin鈥 0B
b010236262ea 7 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo鈥 0B
550f564f074f