实验:构建第一个Docker镜像
Posted hunpi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验:构建第一个Docker镜像相关的知识,希望对你有一定的参考价值。
概述
docker的关键作用:可靠地重现并简便地管理和分享开发环境,可以通过docker镜像实现漏洞环境的复用,实现一次搭建、终身受用的效果。Docker官网地址:hub.docker.com
网上有一些Docker镜像的相关文章,但基本上没有实现整个构建流程的文章,所以在收集资料的基础上完成了这篇文章,完整实现了Docker镜像的寻找、封装、上传的流程,并且记录了涉及的细节问题。
安装Ubuntu镜像并下载常用软件:使用Win10系统。后续换了MacBook,前期命令相同,打包镜像并上传到仓库部分,使用Mac操作系统。
本篇文章的目的,是找到Ubuntu版本的初始docker镜像,上传到自己的docker仓库,方便以后搭建Ubuntu靶场环境和镜像。再远一点,计划把每次搭建的漏洞环境都打包成docker镜像上传到docker仓库。
学习计划:书籍、网络技术文章。
(1)首选书籍:在图书馆找到指导书籍《Docker实践-伊恩·米尔》,该书籍编写时,参考的Docker版本是1.9。
在代码天地https://www.codetd.com/article/236880找到该书籍第一版的PDF,下载后发现只有前一章内容。
寻找和准备镜像
第一部分:寻找并安装镜像。下载官网仓库的Ubuntu镜像,并进入docker镜像。
第二部分:简单处理镜像。查看Ubuntu镜像的系统信息,以及已有软件列表,更新apt安装包管理工具,安装vim编辑器,安装ufw并关闭防火墙。ping百度测试连通性。在根目录下创建标识文件builder.txt,内容build by hunpi。
第三部分:重新打包镜像。注册仓库,把镜像上传到仓库。
寻找镜像模板
搜索"docker构建镜像",找到菜鸟教程的docker安装部分,
访问 Ubuntu 镜像库地址: https://hub.docker.com/_/ubuntu?tab=tags&page=1,发现官网的Ubuntu的docker镜像只有几十MB。
计划下载Ubuntu18.04,也就是18年4月发布的Ubuntu版本,下载到本地查看镜像大小是63.1MB。下载后简单查看系统信息和已有软件包,安装vim编辑器。打包成docker镜像,上传到docker仓库。
准备镜像模板
Kali2020虚拟机还有25GB容量,选择作为docker系列实验的环境。Kali虚拟机已安装docker,所以省略安装过程。开启Kali虚拟机,确保网络连通性,运行命令拉取Ubuntu18.04镜像。
测试网络连通性:ping baidu.com
下载Ubuntu模板镜像:docker pull ubuntu:18.04
查看本地镜像:docker images
随机映射端口创建容器:docker run -it -d -P 7d0d8fa37224
查看已开启的容器:docker ps
进入容器内部:docker exec -it a347e886661e /bin/bash
更新包管理工具、安装常用的软件
更新apt安装包管理工具:apt-get update
查看自带软件列表:dpkg -l
安装vim:apt-get install vim
安装防火墙管理工具ufw:apt-get install ufw
关闭防火墙(搁置):ufw disable
ERROR: problem running ufw-init。iptables v1.6.1: can't initialize iptables table `filter': Permission denied (you must be root)
解决办法:需要在开启容器时,添加-privileged参数。
安装ping命令:apt-get install inetutils-ping
查看镜像ip地址:hostname -i
测试网络连通性(互通):ping baidu.com。ping 192.168.70.142
创建/builder.txt:# build by pumpkin
Ubuntu自带软件列表如下,没有curl和wget等软件:
root@a347e886661e:/# dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-=====================================-=======================-=======================-================================================================================
ii adduser 3.116ubuntu1 all add and remove users and groups
ii apt 1.6.13 amd64 commandline package manager
ii base-files 10.1ubuntu2.10 amd64 Debian base system miscellaneous files
ii base-passwd 3.5.44 amd64 Debian base system master password and group files
ii bash 4.4.18-2ubuntu1.2 amd64 GNU Bourne Again SHell
ii bsdutils 1:2.31.1-0.4ubuntu3.7 amd64 basic utilities from 4.4BSD-Lite
ii bzip2 1.0.6-8.1ubuntu0.2 amd64 high-quality block-sorting file compressor - utilities
ii coreutils 8.28-1ubuntu1 amd64 GNU core utilities
ii dash 0.5.8-2.10 amd64 POSIX-compliant shell
ii debconf 1.5.66ubuntu1 all Debian configuration management system
ii debianutils 4.8.4 amd64 Miscellaneous utilities specific to Debian
ii diffutils 1:3.6-1 amd64 File comparison utilities
ii dpkg 1.19.0.5ubuntu2.3 amd64 Debian package management system
ii e2fsprogs 1.44.1-1ubuntu1.3 amd64 ext2/ext3/ext4 file system utilities
ii fdisk 2.31.1-0.4ubuntu3.7 amd64 collection of partitioning utilities
ii findutils 4.6.0+git+20170828-2 amd64 utilities for finding files--find, xargs
ii gcc-8-base:amd64 8.4.0-1ubuntu1~18.04 amd64 GCC, the GNU Compiler Collection (base package)
ii gpgv 2.2.4-1ubuntu1.4 amd64 GNU privacy guard - signature verification tool
ii grep 3.1-2build1 amd64 GNU grep, egrep and fgrep
ii gzip 1.6-5ubuntu1 amd64 GNU compression utilities
ii hostname 3.20 amd64 utility to set/show the host name or domain name
ii init-system-helpers 1.51 all helper tools for all init systems
ii libacl1:amd64 2.2.52-3build1 amd64 Access control list shared library
ii libapt-pkg5.0:amd64 1.6.13 amd64 package management runtime library
ii libattr1:amd64 1:2.4.47-2build1 amd64 Extended attribute shared library
ii libaudit-common 1:2.8.2-1ubuntu1.1 all Dynamic library for security auditing - common files
ii libaudit1:amd64 1:2.8.2-1ubuntu1.1 amd64 Dynamic library for security auditing
ii libblkid1:amd64 2.31.1-0.4ubuntu3.7 amd64 block device ID library
ii libbz2-1.0:amd64 1.0.6-8.1ubuntu0.2 amd64 high-quality block-sorting file compressor library - runtime
ii libc-bin 2.27-3ubuntu1.4 amd64 GNU C Library: Binaries
ii libc6:amd64 2.27-3ubuntu1.4 amd64 GNU C Library: Shared libraries
ii libcap-ng0:amd64 0.7.7-3.1 amd64 An alternate POSIX capabilities library
ii libcom-err2:amd64 1.44.1-1ubuntu1.3 amd64 common error description library
ii libdb5.3:amd64 5.3.28-13.1ubuntu1.1 amd64 Berkeley v5.3 Database Libraries [runtime]
ii libdebconfclient0:amd64 0.213ubuntu1 amd64 Debian Configuration Management System (C-implementation library)
ii libext2fs2:amd64 1.44.1-1ubuntu1.3 amd64 ext2/ext3/ext4 file system libraries
ii libfdisk1:amd64 2.31.1-0.4ubuntu3.7 amd64 fdisk partitioning library
ii libffi6:amd64 3.2.1-8 amd64 Foreign Function Interface library runtime
ii libgcc1:amd64 1:8.4.0-1ubuntu1~18.04 amd64 GCC support library
ii libgcrypt20:amd64 1.8.1-4ubuntu1.2 amd64 LGPL Crypto library - runtime library
ii libgmp10:amd64 2:6.1.2+dfsg-2 amd64 Multiprecision arithmetic library
ii libgnutls30:amd64 3.5.18-1ubuntu1.4 amd64 GNU TLS library - main runtime library
ii libgpg-error0:amd64 1.27-6 amd64 library for common error values and messages in GnuPG components
ii libhogweed4:amd64 3.4-1ubuntu0.1 amd64 low level cryptographic library (public-key cryptos)
ii libidn2-0:amd64 2.0.4-1.1ubuntu0.2 amd64 Internationalized domain names (IDNA2008/TR46) library
ii liblz4-1:amd64 0.0~r131-2ubuntu3.1 amd64 Fast LZ compression algorithm library - runtime
ii liblzma5:amd64 5.2.2-1.3 amd64 XZ-format compression library
ii libmount1:amd64 2.31.1-0.4ubuntu3.7 amd64 device mounting library
ii libncurses5:amd64 6.1-1ubuntu1.18.04 amd64 shared libraries for terminal handling
ii libncursesw5:amd64 6.1-1ubuntu1.18.04 amd64 shared libraries for terminal handling (wide character support)
ii libnettle6:amd64 3.4-1ubuntu0.1 amd64 low level cryptographic library (symmetric and one-way cryptos)
ii libp11-kit0:amd64 0.23.9-2ubuntu0.1 amd64 library for loading and coordinating access to PKCS#11 modules - runtime
ii libpam-modules:amd64 1.1.8-3.6ubuntu2.18.04. amd64 Pluggable Authentication Modules for PAM
ii libpam-modules-bin 1.1.8-3.6ubuntu2.18.04. amd64 Pluggable Authentication Modules for PAM - helper binaries
ii libpam-runtime 1.1.8-3.6ubuntu2.18.04. all Runtime support for the PAM library
ii libpam0g:amd64 1.1.8-3.6ubuntu2.18.04. amd64 Pluggable Authentication Modules library
ii libpcre3:amd64 2:8.39-9 amd64 Old Perl 5 Compatible Regular Expression Library - runtime files
ii libprocps6:amd64 2:3.3.12-3ubuntu1.2 amd64 library for accessing process information from /proc
ii libseccomp2:amd64 2.5.1-1ubuntu1~18.04.1 amd64 high level interface to Linux seccomp filter
ii libselinux1:amd64 2.7-2build2 amd64 SELinux runtime shared libraries
ii libsemanage-common 2.7-2build2 all Common files for SELinux policy management libraries
ii libsemanage1:amd64 2.7-2build2 amd64 SELinux policy management library
ii libsepol1:amd64 2.7-1 amd64 SELinux library for manipulating binary security policies
ii libsmartcols1:amd64 2.31.1-0.4ubuntu3.7 amd64 smart column output alignment library
ii libss2:amd64 1.44.1-1ubuntu1.3 amd64 command-line interface parsing library
ii libstdc++6:amd64 8.4.0-1ubuntu1~18.04 amd64 GNU Standard C++ Library v3
ii libsystemd0:amd64 237-3ubuntu10.47 amd64 systemd utility library
ii libtasn1-6:amd64 4.13-2 amd64 Manage ASN.1 structures (runtime)
ii libtinfo5:amd64 6.1-1ubuntu1.18.04 amd64 shared low-level terminfo library for terminal handling
ii libudev1:amd64 237-3ubuntu10.47 amd64 libudev shared library
ii libunistring2:amd64 0.9.9-0ubuntu2 amd64 Unicode string library for C
ii libuuid1:amd64 2.31.1-0.4ubuntu3.7 amd64 Universally Unique ID library
ii libzstd1:amd64 1.3.3+dfsg-2ubuntu1.2 amd64 fast lossless compression algorithm
ii login 1:4.5-1ubuntu2 amd64 system login tools
ii lsb-base 9.20170808ubuntu1 all Linux Standard Base init script functionality
ii mawk 1.3.3-17ubuntu3 amd64 a pattern scanning and text processing language
ii mount 2.31.1-0.4ubuntu3.7 amd64 tools for mounting and manipulating filesystems
ii ncurses-base 6.1-1ubuntu1.18.04 all basic terminal type definitions
ii ncurses-bin 6.1-1ubuntu1.18.04 amd64 terminal-related programs and man pages
ii passwd 1:4.5-1ubuntu2 amd64 change and administer password and group data
ii perl-base 5.26.1-6ubuntu0.5 amd64 minimal Perl system
ii procps 2:3.3.12-3ubuntu1.2 amd64 /proc file system utilities
ii sed 4.4-2 amd64 GNU stream editor for filtering/transforming text
ii sensible-utils 0.0.12 all Utilities for sensible alternative selection
ii sysvinit-utils 2.88dsf-59.10ubuntu1 amd64 System-V-like utilities
ii tar 1.29b-2ubuntu0.2 amd64 GNU version of the tar archiving utility
ii ubuntu-keyring 2018.09.18.1~18.04.2 all GnuPG keys of the Ubuntu archive
ii util-linux 2.31.1-0.4ubuntu3.7 amd64 miscellaneous system utilities
ii zlib1g:amd64 1:1.2.11.dfsg-0ubuntu2 amd64 compression library - runtime
Dockerfile
dockerfile的指令会给镜像封装一层,可以用于自动化构建镜像。把刚才执行的命令写入名为Dockerfile的文件:
docker有300MB,ufw有900kb,下载后为了空间又都删了。软件大小标记:
FROM Ubuntu18.04
RUN echo 'It's built by pumpkin' > /builder.txt \\
&& apt-get update
&& apt-get install vim(2856kb)
&& apt-get install inetutils-ping(344kb)
&& apt-get install curl(396kb)
把Dockerfile文件放到空目录下,然后使用构建命令:docker build -t nginx:v3(镜像名称:镜像标签) .
。执行命令后查看docker images
,存在v3镜像说明构建成功。
安装这些软件之后,查看镜像已有的软件清单:
root@b246bc02c8d7:/# dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii adduser 3.116ubuntu1 all add and remove users and groups
ii apt 1.6.13 amd64 commandline package manager
ii base-files 10.1ubuntu2. amd64 Debian base system miscellaneous
ii base-passwd 3.5.44 amd64 Debian base system master passwor
ii bash 4.4.18-2ubun amd64 GNU Bourne Again SHell
ii bsdutils 1:2.31.1-0.4 amd64 basic utilities from 4.4BSD-Lite
ii bzip2 1.0.6-8.1ubu amd64 high-quality block-sorting file c
ii coreutils 8.28-1ubuntu amd64 GNU core utilities
ii dash 0.5.8-2.10 amd64 POSIX-compliant shell
ii debconf 1.5.66ubuntu all Debian configuration management s
ii debianutils 4.8.4 amd64 Miscellaneous utilities specific
ii diffutils 1:3.6-1 amd64 File comparison utilities
ii dpkg 1.19.0.5ubun amd64 Debian package management system
ii e2fsprogs 1.44.1-1ubun amd64 ext2/ext3/ext4 file system utilit
ii fdisk 2.31.1-0.4ub amd64 collection of partitioning utilit
ii file 1:5.32-2ubun amd64 Recognize the type of data in a f
ii findutils 4.6.0+git+20 amd64 utilities for finding files--find
ii gcc-8-base:amd 8.4.0-1ubunt amd64 GCC, the GNU Compiler Collection
ii gpgv 2.2.4-1ubunt amd64 GNU privacy guard - signature ver
ii grep 3.1-2build1 amd64 GNU grep, egrep and fgrep
ii gzip 1.6-5ubuntu1 amd64 GNU compression utilities
ii hostname 3.20 amd64 utility to set/show the host name
ii inetutils-ping 2:1.9.4-3 amd64 ICMP echo tool
ii init-system-he 1.51 all helper tools for all init systems
ii iptables 1.6.1-2ubunt amd64 administration tools for packet f
ii libacl1:amd64 2.2.52-3buil amd64 Access control list shared librar
ii libapt-pkg5.0: 1.6.13 amd64 package management runtime librar
ii libattr1:amd64 1:2.4.47-2bu amd64 Extended attribute shared library
ii libaudit-commo 1:2.8.2-1ubu all Dynamic library for security audi
ii libaudit1:amd6 1:2.8.2-1ubu amd64 Dynamic library for security audi
ii libblkid1:amd6 2.31.1-0.4ub amd64 block device ID library
ii libbz2-1.0:amd 1.0.6-8.1ubu amd64 high-quality block-sorting file c
ii libc-bin 2.27-3ubuntu amd64 GNU C Library: Binaries
ii libc6:amd64 2.27-3ubuntu amd64 GNU C Library: Shared libraries
ii libcap-ng0:amd 0.7.7-3.1 amd64 An alternate POSIX capabilities l
ii libcom-err2:am 1.44.1-1ubun amd64 common error description library
ii libdb5.3:amd64 5.3.28-13.1u amd64 Berkeley v5.3 Database Libraries
ii libdebconfclie 0.213ubuntu1 amd64 Debian Configuration Management S
ii libexpat1:amd6 2.2.5-3ubunt amd64 XML parsing C library - runtime l
ii libext2fs2:amd 1.44.1-1ubun amd64 ext2/ext3/ext4 file system librar
ii libfdisk1:amd6 2.31.1-0.4ub amd64 fdisk partitioning library
ii libffi6:amd64 3.2.1-8 amd64 Foreign Function Interface librar
ii libgcc1:amd64 1:8.4.0-1ubu amd64 GCC support library
ii libgcrypt20:am 1.8.1-4ubunt amd64 LGPL Crypto library - runtime lib
ii libgmp10:amd64 2:6.1.2+dfsg amd64 Multiprecision arithmetic library
ii libgnutls30:am 3.5.18-1ubun amd64 GNU TLS library - main runtime li
ii libgpg-error0: 1.27-6 amd64 library for common error values a
ii libgpm2:amd64 1.20.7-5 amd64 General Purpose Mouse - shared li
ii libhogweed4:am 3.4-1ubuntu0 amd64 low level cryptographic library (
ii libidn2-0:amd6 2.0.4-1.1ubu amd64 Internationalized domain names (I
ii libip4tc0:amd6 1.6.1-2ubunt amd64 netfilter libip4tc library
ii libip6tc0:amd6 1.6.1-2ubunt amd64 netfilter libip6tc library
ii libiptc0:amd64 1.6.1-2ubunt amd64 netfilter libiptc library
ii liblz4-1:amd64 0.0~r131-2ub amd64 Fast LZ compression algorithm lib
ii liblzma5:amd64 5.2.2-1.3 amd64 XZ-format compression library
ii libmagic-mgc 1:5.32-2ubun amd64 File type determination library u
ii libmagic1:amd6 1:5.32-2ubun amd64 Recognize the type of data in a f
ii libmnl0:amd64 1.0.4-2 amd64 minimalistic Netlink communicatio
ii libmount1:amd6 2.31.1-0.4ub amd64 device mounting library
ii libmpdec2:amd6 2.4.2-1ubunt amd64 library for decimal floating poin
ii libncurses5:am 6.1-1ubuntu1 amd64 shared libraries for terminal han
ii libncursesw5:a 6.1-1ubuntu1 amd64 shared libraries for terminal han
ii libnetfilter-c 1.0.6-2 amd64 Netfilter netlink-conntrack libra
ii libnettle6:amd 3.4-1ubuntu0 amd64 low level cryptographic library (
ii libnfnetlink0: 1.0.1-3 amd64 Netfilter netlink library
ii libp11-kit0:am 0.23.9-2ubun amd64 library for loading and coordinat
ii libpam-modules 1.1.8-3.6ubu amd64 Pluggable Authentication Modules
ii libpam-modules 1.1.8-3.6ubu amd64 Pluggable Authentication Modules
ii libpam-runtime 1.1.8-3.6ubu all Runtime support for the PAM libra
ii libpam0g:amd64 1.1.8-3.6ubu amd64 Pluggable Authentication Modules
ii libpcre3:amd64 2:8.39-9 amd64 Old Perl 5 Compatible Regular Exp
ii libprocps6:amd 2:3.3.12-3ub amd64 library for accessing process inf
ii libpython3-std 3.6.7-1~18.0 amd64 interactive high-level object-ori
ii libpython3.6:a 3.6.9-1~18.0 amd64 Shared Python runtime library (ve
ii libpython3.6-m 3.6.9-1~18.0 amd64 Minimal subset of the Python lang
ii libpython3.6-s 3.6.9-1~18.0 amd64 Interactive high-level object-ori
ii libreadline7:a 7.0-3 amd64 GNU readline and history librarie
ii libseccomp2:am 2.5.1-1ubunt amd64 high level interface to Linux sec
ii libselinux1:am 2.7-2build2 amd64 SELinux runtime shared libraries
ii libsemanage-co 2.7-2build2 all Common files for SELinux policy m
ii libsemanage1:a 2.7-2build2 amd64 SELinux policy management library
ii libsepol1:amd6 2.7-1 amd64 SELinux library for manipulating
ii libsmartcols1: 2.31.1-0.4ub amd64 smart column output alignment lib
ii libsqlite3-0:a 3.22.0-1ubun amd64 SQLite 3 shared library
ii libss2:amd64 1.44.1-1ubun amd64 command-line interface parsing li
ii libssl1.1:amd6 1.1.1-1ubunt amd64 Secure Sockets Layer toolkit - sh
ii libstdc++6:amd 8.4.0-1ubunt amd64 GNU Standard C++ Library v3
ii libsystemd0:am 237-3ubuntu1 amd64 systemd utility library
ii libtasn1-6:amd 4.13-2 amd64 Manage ASN.1 structures (runtime)
ii libtinfo5:amd6 6.1-1ubuntu1 amd64 shared low-level terminfo library
ii libudev1:amd64 237-3ubuntu1 amd64 libudev shared library
ii libunistring2: 0.9.9-0ubunt amd64 Unicode string library for C
ii libuuid1:amd64 2.31.1-0.4ub amd64 Universally Unique ID library
ii libxtables12:a 1.6.1-2ubunt amd64 netfilter xtables library
ii libzstd1:amd64 1.3.3+dfsg-2 amd64 fast lossless compression algorit
ii login 1:4.5-1ubunt amd64 system login tools
ii lsb-base 9.20170808ub all Linux Standard Base init script f
ii mawk 1.3.3-17ubun amd64 a pattern scanning and text proce
ii mime-support 3.60ubuntu1 all MIME files 'mime.types' & 'mailca
ii mount 2.31.1-0.4ub amd64 tools for mounting and manipulati
ii multiarch-supp 2.27-3ubuntu amd64 Transitional package to ensure mu
ii ncurses-base 6.1-1ubuntu1 all basic terminal type definitions
ii ncurses-bin 6.1-1ubuntu1 amd64 terminal-related programs and man
ii netbase 5.4 all Basic TCP/IP networking system
ii passwd 1:4.5-1ubunt amd64 change and administer password an
ii perl-base 5.26.1-6ubun amd64 minimal Perl system
ii procps 2:3.3.12-3ub amd64 /proc file system utilities
ii python3 3.6.7-1~18.0 amd64 interactive high-level object-ori
ii python3-minima 3.6.7-1~18.0 amd64 minimal subset of the Python lang
ii python3.6 3.6.9-1~18.0 amd64 Interactive high-level object-ori
ii python3.6-mini 3.6.9-1~18.0 amd64 Minimal subset of the Python lang
ii readline-commo 7.0-3 all GNU readline and history librarie
ii sed 4.4-2 amd64 GNU stream editor for filtering/t
ii sensible-utils 0.0.12 all Utilities for sensible alternativ
ii sysvinit-utils 2.88dsf-59.1 amd64 System-V-like utilities
ii tar 1.29b-2ubunt amd64 GNU version of the tar archiving
ii ubuntu-keyring 2018.09.18.1 all GnuPG keys of the Ubuntu archive
ii ucf 3.0038 all Update Configuration File(s): pre
ii ufw 0.36-0ubuntu all program for managing a Netfilter
ii util-linux 2.31.1-0.4ub amd64 miscellaneous system utilities
ii vim 2:8.0.1453-1 amd64 Vi IMproved - enhanced vi editor
ii vim-common 2:8.0.1453-1 all Vi IMproved - Common files
ii vim-runtime 2:8.0.1453-1 all Vi IMproved - Runtime files
ii xxd 2:8.0.1453-1 amd64 tool to make (or reverse) a hex d
ii xz-utils 5.2.2-1.3 amd64 XZ-format compression utilities
ii zlib1g:amd64 1:1.2.11.dfs amd64 compression library - runtime
打包容器并上传到仓库
把容器打包成镜像
退出镜像,使用docker commit
命令把容器打包成镜像,发现有684MB。
进入容器,把docker删除掉,重新打包成镜像,发现有364MB。
docker commit b246bc02c8d7 ubuntu18:base1 # 把容器打包成镜像
docker images # 查看镜像
dpkg -l | grep docker # 查看docker相关软件
apt remove --purge docker-ce # 逐个删除
docker rmi 镜像id # 删除镜像
为了避免镜像的臃肿,决定在官方Ubuntu镜像的基础上重新开启一个容器,只执行两个命令,vim相关程序有61mb,用得不多就不下载了。退出容器,把容器构建成镜像,大小是100MB。
apt-get update(22.9mb) # 更新包管理工具
echo "The First Image Of pumpkin, Which only exec 'apt-get update'." > builder
# 把容器打包成镜像(镜像命名有一定规则,必须以docker的个人id开头)
错误示范1:docker commit -a pumpkin 925f880c63cf pumpkin/ubuntu18:demo
错误示范2:docker commit -a pumpkin 925f880c63cf hunpi/pumpkin/ubuntu18:demo
正确示范:docker commit -a pumpkin 925f880c63cf hunpi/ubuntu18:demo
把镜像上传到公网
(1)注册docker账号:地址https://hub.docker.com;(2)命令后登陆账号:docker login --username=hunpi。
(3)上传镜像:docker push 镜像名:标签。发生报错:denied: requested access to the resource is denied。查询文章知道,镜像名称必须以docker的个人ID开头。
(4)验证:docker search hunpi。(漂亮!)不过Description描述是空的,下次需要改进,推测描述信息由docker commit -m "message"
决定。
接下来可以快乐地复现了,不用再担心环境的复用问题。(但愿)
参考文章和链接
《Docker 安装 Ubuntu》-菜鸟教程
https://www.runoob.com/docker/docker-install-ubuntu.html
Docker官方仓库-Ubuntu镜像地址
https://hub.docker.com/_/ubuntu?tab=tags&page=1&ordering=last_updated
《如何制作Docker镜像(image)?》-知乎,2020-04
https://zhuanlan.zhihu.com/p/122380334
以上是关于实验:构建第一个Docker镜像的主要内容,如果未能解决你的问题,请参考以下文章