docker镜像操作
镜像制作:
- 第一种:docker commit
语法: docker commit <container ID/image_name> <新镜像名>
例:创建含ftp的镜像
1、创建实例并安装ftp
[root@localhost ~]# docker run -it --name centos_ftp docker.io/centos:latest bash
[root@7bce31aa8914 /]# yum -y install vsftpd
2、创建ftp镜像
[root@localhost ~]# docker commit centos_ftp docker.io/centos:ftp sha256:66b72f7bcd98e2e343e68e64a415de0b5ad99af3e6e7b15a7f40387369479016
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/centos ftp 66b72f7bcd98 39 seconds ago 282 MB docker.io/centos latest 49f7960eb7e4 4 weeks ago 200 MB
- 第二种:docker build
语法:docker build -t <父镜像名:标签> <Dockerfile文件路径>
1、创建Dockerfile
[root@localhost ~]# mkdir /docker-build
[root@localhost ~]# vim /docker-build/Dockerfile FROM docker.io/centos:latest MAINTAINER <lnhxzwb@126.com> RUN yum -y install httpd RUN echo "/usr/sbin/httpd -DFOREGROUND" > /usr/local/bin/http.sh RUN echo "docker image build" > /var/www/html/index.html RUN chmod 755 /usr/local/bin/http.sh CMD /usr/local/bin/http.sh
注:CMD只能一个,多个时只执行最后一个,docker 1.3(不含1.3)之前版本命令需[ ]括起来
2、创建镜像
[root@localhost ~]# docker build -t docker.io/centos:httpd /docker-build/ Step 1/7 : FROM docker.io/centos:latest ---> 49f7960eb7e4 ...... Step 7/7 : CMD /usr/local/bin/http.sh ---> Running in 906ae36c8aab ---> 75e255961f28 Removing intermediate container 906ae36c8aab Successfully built 75e255961f28
[root@localhost docker-build]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/centos httpd 75e255961f28 53 seconds ago 314 MB docker.io/centos ftp 66b72f7bcd98 24 minutes ago 282 MB docker.io/centos latest 49f7960eb7e4 4 weeks ago 200 MB
镜像发布:
- 第一种:Save Image To TarBall
语法:docker save -o <导出的镜像名.tar> <本地镜像名:标签>
[root@localhost ~]# docker save -o docker.io-centos-httpd-image.tar docker.io/centos:httpd
[root@localhost ~]# ll -h -rw------- 1 root root 309M Jul 4 11:26 docker.io-centos-httpd-image.tar
- 第二种:发布到docker hub
1、在https://hub.docker.com上注册用户
2、登陆hub
语法: docker login -u <用户名> -p <密码> -e <mail>
3、上传
语法:docker push <镜像名:标签>
[root@localhost ~]# docker push docker.io/centos:httpd
温馨提示:如无特殊说明,本站文章均为作者原创,转载时请注明出处及相应链接!