Docker镜像的构建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker镜像的构建相关的知识,希望对你有一定的参考价值。
容器内部像linux一样操作,然后提交容器成镜像
Dokcerfile提交镜像
一
创建一个容器
[[email protected] ~]#docker run --name mynginx01 -it centos [[email protected] ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 84bcc294325b nginx "nginx -g ‘daemon off" 3 seconds ago Up 3 seconds
2.此时已经进入容器
yum -y install wget wget -O /etc/yum.repos.d/epel.repo yum -y install nginx vim /etc/nginx /nginx.conf ... daemon off; 退出
3,制作镜像
[[email protected] ~]# docker commit -m "mynginx01" be750c11ab1e mynginx/mynginx:v1 sha256:5143358c3833b4ee5a40b847d86dee072dc7c0bade9358e7d83323d6349784b0 [[email protected] ~]# mynginx/mynginx:v1 仓库/镜像名称:版本标签 [[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mynginx/mynginx v1 5143358c3833 41 seconds ago 340.1 MB
二.Dokcerfile制作镜像
[[email protected] dockerfile]# cat Dockerfile FROM centos MAINTAINER liuhaixiao RUN yum -y install wget RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm RUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo RUN yum clean all && yum install nginx -y RUN echo "daemon off;" >>/etc/nginx/nginx.conf ADD index.html /usr/share/nginx/html/index.html EXPOSE 80 CMD ["nginx"] [[email protected] dockerfile]# cat index.html hello liuhx [[email protected] dockerfile]# pwd /root/dockerfile [[email protected] dockerfile]#
构建镜像
cd /root/dockerfile Docker build -t mynginx/mynginx03:03 ./
[[email protected] dockerfile]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mynginx/mynginx03 v3 8c81f51923e5 2 minutes ago 374.6 MB
启动容器:
[[email protected] dockerfile]# docker run -d --name nginx007 -p 86:80 mynginx/mynginx03:v3 6f2501177ac00e064b22c6c3045b973dc41935e82180753a21a14f3224f5f323
本文出自 “砖家博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1889520
以上是关于Docker镜像的构建的主要内容,如果未能解决你的问题,请参考以下文章
构建Docker镜像两种方式的比较-Dockerfile方式和S2I方式
Docker删除报错:Error response from daemon: conflict: unable to delete 08b152afcfae (must be forced)(代码片段