$ docker commit -m='done some things' -a='ni9ne' cc7adb4b2145 ni9ne/ubuntu:V1
1 2 3 4 5 6 7 8 9 10 11 12 13
sha256:3de2fb0fa6533c64256e085959e358030544bbd819154a4ccb04ab902ffae6e0 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ni9ne/ubuntu v1 3de2fb0fa653 12 seconds ago 137MB httpd latest 3dd970e6b110 10 days ago 138MB ubuntu latest 9140108b62dc 3 weeks ago 72.9MB ubuntu 15.10 9b9cb95443b5 4 years ago 137MB ubuntu 13.10 7f020f7bf345 6 years ago 185MB $ docker run -ti ni9ne/ubuntu ni9ne/ubuntu ni9ne/ubuntu:v1 $ docker run -ti ni9ne/ubuntu:v1 /bin/bash root@f8cab436a299:/#
6.创建镜像
1
$ docker build -t ni9ne/centos6.7 docker/
指定以docker文件夹下的Dockerfile创建名为ni9ne/centos6.7的镜像
1
$ vi docker/Dockerfile
1 2 3 4 5 6 7 8 9 10
1 FROM centos:6.7 2 MAINTAINER Ni9ne "ni9ne@outlook.com" 3 4 RUN /bin/echo'root:123456' | chpasswd 5 RUN useradd ni9ne 6 RUN /bin/echo'ni9ne:ni9ne' | chpasswd 7 RUN /bin/echo -e"LANG=\"en_US.UTF-8\"" > /etc/default/local 8 EXPOSE 22 9 EXPOSE 80 10 CMD /usr/sbin/sshd -D
查看创建镜像
1 2 3 4
ubuntu@ubuntu:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ni9ne/centos6.7 latest 95cc1d4ddbfe 11 minutes ago 191MB ...
7.为镜像添加tag
1
$ docker tag 95cc1d4ddbfe ni9nee/centos6.7:dev
1 2 3 4 5
ubuntu@ubuntu:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ni9nee/centos6.7 dev.1 95cc1d4ddbfe 13 minutes ago 191MB ni9ne/centos6.7 latest 95cc1d4ddbfe 13 minutes ago 191MB ...
$ docker run -it --rm -h host_ubuntu --dns=114.114.114.114 --dns-search=test.com ubuntu
1 2 3 4 5 6 7 8
--rm Automatically remove the container when it exits 容器退出时自动清理容器内部的文件系统。 -h, --hostname string Container host name 设定容器的主机名,它会被写到容器内的 /etc/hostname 和 /etc/hosts --dns=IP_ADDRESS Set custom DNS servers 添加 DNS 服务器到容器的 /etc/resolv.conf 中,让容器用这个服务器来解析所有不在 /etc/hosts 中的主机名 --dns-search=DOMAIN Set custom DNS search domains 设定容器的搜索域,当设定搜索域为 .example.com 时,在搜索一个名为 host 的主机时,DNS 不仅搜索 host,还会搜索 host.example.com。