- 容器内部像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
时间: 2024-10-06 04:23:25