root@blacsheep-myubuntu:/home/blacsheep# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 16.10 7d3f705d307c 6 months ago 107MB training/webapp latest 6fae60ef3446 2 years ago 349MB root@blacsheep-myubuntu:/home/blacsheep#
root@blacsheep-myubuntu:/home/blacsheep# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 0458a4468cbc 2 days ago 112MB ubuntu 16.10 7d3f705d307c 6 months ago 107MB training/webapp latest 6fae60ef3446 2 years ago 349MB root@blacsheep-myubuntu:/home/blacsheep#
root@blacsheep-myubuntu:/home/blacsheep# docker search httpd NAME DESCRIPTION STARS OFFICIAL AUTOMATED httpd The Apache HTTP Server Project 1470 [OK] hypriot/rpi-busybox-httpd Raspberry Pi compatible Docker Image with a … 40 centos/httpd 15 [OK] centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or bui… 8 armhf/httpd The Apache HTTP Server Project 8 macadmins/netboot-httpd use in combination with bruienne/bsdpy 4 [OK] lolhens/httpd Apache httpd 2 Server 2 [OK] salim1983hoop/httpd24 Dockerfile running apache config 2 [OK] fboaventura/dckr-httpd Small footprint http server to use with othe… 1 [OK] rgielen/httpd-image-simple Docker image for simple Apache httpd based o… 1 [OK] lead4good/httpd-fpm httpd server which connects via fcgi proxy h… 1 [OK] epflidevelop/os-wp-httpd WP httpd 1 [OK] rgielen/httpd-image-php5 Docker image for Apache httpd with PHP 5 bas… 1 [OK] publici/httpd httpd:latest 0 [OK] tplatform/aws-linux-httpd24-php70 aws-linux-httpd24-php70 0 [OK] dockerpinata/httpd 0 trollin/httpd 0 manasip/httpd 0 manageiq/httpd Container with httpd, built on CentOS for Ma… 0 [OK] jbpt/httpd 0 [OK] fintaffy/fintaffy-httpd 0 efrecon/httpd A micro-sized httpd. Start serving files in … 0 [OK] ppc64le/httpd The Apache HTTP Server Project 0 sbutler/pie-httpd PIE httpd server 0 camptocamp/os-wp-httpd Wordpress httpd 0 [OK] root@blacsheep-myubuntu:/home/blacsheep#
root@blacsheep-myubuntu:/home/blacsheep# docker images REPOSITORY TAG IMAGE ID CREATED SIZE blacsheep/ubuntu v1 3846343d3b39 About a minute ago 107MB httpd latest 2e202f453940 2 days ago 179MB ubuntu latest 0458a4468cbc 2 days ago 112MB ubuntu 16.10 7d3f705d307c 6 months ago 107MB training/webapp latest 6fae60ef3446 2 years ago 349MB root@blacsheep-myubuntu:/home/blacsheep#
这样就可以使用新的镜像来创建容器了
1 2
root@blacsheep-myubuntu:/home/blacsheep# docker run -t -i blacsheep/ubuntu:v1 /bin/bash root@02b45e36003d:/#
root@blacsheep-myubuntu:/home/blacsheep# docker build -t blacsheep/ubuntu:dockerfile . ERRO[0036] Can't add file /home/blacsheep/.gnupg/S.gpg-agent to tar: archive/tar: sockets not supported Sending build context to Docker daemon 2.19GB Step 1/8 : From ubuntu:16.04 16.04: Pulling from library/ubuntu 1be7f2b886e8: Already exists 6fbc4a21b806: Already exists c71a6f8e1378: Already exists 4be3072e5a37: Already exists 06c6d2f59700: Already exists Digest: sha256:2b80e7fbfd1b0a3784dd0e55fb6f2750ebc33e596c2ccee5201ecf018ac5ae05 Status: Downloaded newer image for ubuntu:16.04 ---> 0458a4468cbc Step 2/8 : RUN /bin/echo 'root:123456' chpasswd ---> Running in b3d12aa12f6c Removing intermediate container b3d12aa12f6c ---> 99c6e9ccdd81 Step 3/8 : RUN useradd blacsheep ---> Running in fe025de84d56 Removing intermediate container fe025de84d56 ---> e5180f2047b3 Step 4/8 : RUN /bin/echo 'blacsheep:123456' chpasswd ---> Running in aa3c30d8f07b Removing intermediate container aa3c30d8f07b ---> 9bda89fa8c14 Step 5/8 : RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/local ---> Running in d63a51e6d430 Removing intermediate container d63a51e6d430 ---> a3b879d7090e Step 6/8 : EXPOSE 22 ---> Running in d2f15040553b Removing intermediate container d2f15040553b ---> 65916c8dda3e Step 7/8 : EXPOSE 80 ---> Running in 62dde9991ee4 Removing intermediate container 62dde9991ee4 ---> 5bf05e8d377f Step 8/8 : CMD /usr/sbin/sshd -D ---> Running in 62528b637ebc Removing intermediate container 62528b637ebc ---> 7ba34ce933fb Successfully built 7ba34ce933fb Successfully tagged blacsheep/ubuntu:dockerfile root@blacsheep-myubuntu:/home/blacsheep# docker images REPOSITORY TAG IMAGE ID CREATED SIZE blacsheep/ubuntu dockerfile 7ba34ce933fb About a minute ago 112MB blacsheep/ubuntu v1 3846343d3b39 22 minutes ago 107MB httpd latest 2e202f453940 2 days ago 179MB ubuntu 16.04 0458a4468cbc 2 days ago 112MB ubuntu latest 0458a4468cbc 2 days ago 112MB ubuntu 16.10 7d3f705d307c 6 months ago 107MB training/webapp latest 6fae60ef3446 2 years ago 349MB root@blacsheep-myubuntu:/home/blacsheep#
最后的docker images也可以看出镜像安装成功了 然后至于用户
1 2 3 4
root@blacsheep-myubuntu:/home/blacsheep# docker run -i -t blacsheep/ubuntu:dockerfile /bin/bash root@1b52c348bf31:/# id blacsheep uid=1000(blacsheep) gid=1000(blacsheep) groups=1000(blacsheep) root@1b52c348bf31:/#
设置镜像标签
使用docker tag命令 比如
1 2 3 4 5 6 7 8 9 10
root@blacsheep-myubuntu:/home/blacsheep# docker tag 7ba34ce933fb blacsheep/ubuntu:practice root@blacsheep-myubuntu:/home/blacsheep# docker images REPOSITORY TAG IMAGE ID CREATED SIZE blacsheep/ubuntu dockerfile 7ba34ce933fb 19 minutes ago 112MB blacsheep/ubuntu practice 7ba34ce933fb 19 minutes ago 112MB blacsheep/ubuntu v1 3846343d3b39 40 minutes ago 107MB httpd latest 2e202f453940 2 days ago 179MB ubuntu 16.10 7d3f705d307c 6 months ago 107MB training/webapp latest 6fae60ef3446 2 years ago 349MB root@blacsheep-myubuntu:/home/blacsheep#