Docker的主要目标:Build,Ship and Run Any App,Anywhere,即通过对应用组件的封装(Packaging)、分发(Distribution)、部署(Deployment)。运行(Runtime)等生命周期的管理,达到应用组件级别的“一次封装,到处运行”。这里的应用组件,既可以是一个Web应用,也可以是一套数据库服务,甚至是一个操作系统。将应用运行在Docker容器上,可以实现跨平台,跨服务器,只需一次配置准备好相关的应用环境,即可实现到处运行,保证研发和生产环境的一致性,解决了应用和运行环境的兼容性问题,从而极大提升了部署效率,减少故障的可能性。
User Namespace允许在各个宿主机的各个容器空间内创建相同的用户名以及相同的用户UID和GID,只是会把用户的作用范围限制在每个容器内,即A容器和B容器可以有相同的用户名称和ID账户,但是此用户的有效范围仅是当前容器内,不能访问另外一个容器内的文件系统,级相互隔离、互不影响、永不相见。
Control groups
Linux Cgroups的全称是Linux Control Groups,是Linux内核的一个功能,最早由Google的工程师(主要是Paul Menage和Rohit Seth)在2006年发起,最早的名称为进程容器(process containers)。在2007年时,因为在Linux内核中,容器(container)这个名词有许多不同的意义,为避免混乱,被重命名为cgroup,并且被合并到2.6.24版的内核中去。自那以后,又添加了很多功能。
Options: -f, --filter filter Filter output based on conditions provided --format string Pretty-print search using a Go template --limit int Max number of search results (default 25) 说明: OFFICIAL:官方 AUTOMATED:使用第三方docker服务来帮助编译镜像,可以在互联网上面直接拉取到镜像,减少了繁琐的编译过程
例:查找centos镜像
[root@centos7 ~]# docker search centos NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official build of CentOS. 7288 [OK] kasmweb/centos-7-desktop CentOS 7 desktop for Kasm Workspaces 24 couchbase/centos7-systemd centos7-systemd images with additional debug… 4 [OK] dokken/centos-7 CentOS 7 image for kitchen-dokken 3 continuumio/centos5_gcc5_base 3 dokken/centos-stream-9 2 dokken/centos-stream-8 2 spack/centos7 CentOS 7 with Spack preinstalled 1 spack/centos6 CentOS 6 with Spack preinstalled 1 datadog/centos-i386 0 dokken/centos-6 CentOS 6 image for kitchen-dokken 0 ustclug/centos Official CentOS Image with USTC Mirror 0 dokken/centos-8 CentOS 8 image for kitchen-dokken 0 corpusops/centos-bare https://github.com/corpusops/docker-images/ 0 bitnami/centos-extras-base 0 corpusops/centos centos corpusops baseimage 0 couchbase/centos-72-java-sdk 0 couchbase/centos-72-jenkins-core 0 couchbase/centos-70-sdk-build 0 bitnami/centos-base-buildpack Centos base compilation image 0 [OK] couchbase/centos-69-sdk-nodevtoolset-build 0 fnndsc/centos-python3 Source for a slim Centos-based Python3 image… 0 [OK] couchbase/centos-69-sdk-build 0 dokken/centos-5 EOL DISTRO: For use with kitchen-dokken, Bas… 0 spack/centos-stream 0
搜索点赞100个以上的镜像
[root@centos7 ~]# docker search --filter=stars=100 centos NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official build of CentOS. 7288 [OK]
REPOSITORY TAG IMAGE ID CREATED SIZE debian latest dd8bae8d259f Less than a second ago 124MB alpine latest 9c6f07244728 12 days ago 5.54MB ubuntu latest df5de72bdb3b 2 weeks ago 77.8MB centos latest 5d0da3dc9764 11 months ago 231MB
Package installation and removal: add Add packages to WORLD and commit changes del Remove packages from WORLD and commit changes
System maintenance: fix Fix, reinstall or upgrade packages without modifying WORLD update Update repository indexes upgrade Install upgrades available from repositories cache Manage the local package cache
Querying package information: info Give detailed information about packages or repositories list List packages matching a pattern or other criteria dot Render dependencies as graphviz graphs policy Show repository policy for packages search Search for packages by name or description
Repository maintenance: index Create repository index file from packages fetch Download packages from global repositories to a local directory manifest Show checksums of package contents verify Verify package integrity and signature
Miscellaneous: audit Audit system for changes stats Show statistics about repositories and installations version Compare package versions or perform tests on version strings
This apk has coffee making abilities. For more information: man 8 apk
docker pull [OPTION] NAME[:TAG|@GIGEST] OPTIONS: -a,--all-tags Download all tagged images in the repository --disable-content-trust Skip image verification (default true) --platform string Set platform if server is multi-platform capable -q,--quit Suppress verbose output NAME:是镜像名,一般的形式 仓库服务器:端口/项目名称/镜像名称 :TAG:即版本号,如果不指定:TAG,则下载最新版镜像
docker images [OPTIONS] [REPOSITORY[:TAG]] docker image ls [OPTIONS] [REPOSITORY[:TAG]] # 常用选项 -q,--quiet Only show numberic IDs -a,--all Show all images (default hides intermediate images) --digests Show digests --no-trunc Don't truncate output -f,--filter filter Filter output based on conditions provided --format string Pretty-print images using a Go template
执行结果的显示信息说明
REPOSITORY # 镜像所属的仓库名称 TAG # 镜像版本号(标识符),默认为latest IMAGE ID # 镜像唯一ID标识,如果ID相同,说明是同一个镜像有多个名称 VREATED # 镜像在仓库中被创建时间 SIZE # 镜像的大小
Repository仓库
由某特定的docker镜像的所有迭代版本组成的镜像仓库
一个Registry中可以存在多个Repository
Repository可分为“顶层仓库”和“用户仓库”
Repository用户仓库名称一般格式为“用户名/仓库名”
每个Repository仓库可以包含多个Tag,每个标签对应一个镜像
镜像导出
利用docker save命令可以将本地镜像导出为一个tar文件,然后复制到其他服务器进行导入使用
docker save [OPTIONS] IMAGE [IMAGE...] # 选项: -o,--output string write to a file,instead of STDOUT
常见用法:
docker save -o /path/file.tar IMAGE1 IMAGE2 ... docker save IMAGE1 IMAGE2... > /path/file.tar
镜像导入
利用docker load 命令可以将镜像导出的压缩文件再导入
docker load [OPTIONS] # 选项 -i,--input string Read from tar archive,instead of STDIN -q,--quiet Suppress the load output
docker rmi [OPTIONS] IMAGE [IMAGE...] docker image rm [OPTIONS] IMAGE [IMAGE...] # 选项 -f,--force Force removal of the image --no-prune Do not delete untagged parents
常见用法:
[root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE debian latest dd8bae8d259f Less than a second ago 124MB alpine latest 9c6f07244728 13 days ago 5.54MB ubuntu latest df5de72bdb3b 2 weeks ago 77.8MB hello-world latest feb5d9fea6a5 11 months ago 13.3kB centos latest 5d0da3dc9764 11 months ago 231MB centos centos7.7.1908 08d05d1d5859 2 years ago 204MB # 根据IMAGE ID删除镜像 [root@centos7 ~]# docker rmi 08d Untagged: centos:centos7.7.1908 Untagged: centos@sha256:50752af5182c6cd5518e3e91d48f7ff0cba93d5d760a67ac140e2d63c4dd9efc Deleted: sha256:08d05d1d5859ebcfb3312d246e2082e46cb307f0e896c9ac097185f0b0b19e56 Deleted: sha256:034f282942cd6c3abf9384601a57f080f8f75cc7f58527db8e07573d9d14ab46 # 根据REPOSITORY名称删除镜像 [root@centos7 ~]# docker rmi centos Untagged: centos:latest Untagged: centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177 Deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6 Deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59 # 删除多个镜像 [root@centos7 ~]# docker rmi debian ubuntu Untagged: debian:latest Untagged: debian@sha256:875e4e2bae4d7ff53fe7f3672b15630439479fd10da081477a14208122fe8f31 Deleted: sha256:dd8bae8d259fed93eb54b3bca0adeb647fc07f6ef16745c8ed4144ada4d51a95 Deleted: sha256:655ed1b7a4286ce965b8942644f665a3aeafac315f023b3d75fabdbd4be12dd0 Untagged: ubuntu:latest Untagged: ubuntu@sha256:34fea4f31bf187bc915536831fd0afc9d214755bf700b5cdb1336c82516d154e Deleted: sha256:df5de72bdb3b711aba4eca685b1f42c722cc8a1837ed3fbd548a9282af2d836d Deleted: sha256:629d9dbab5edeac7fa51f205839d7f9bb629a5e83548da3a183fb66c22fe7af7 # 删除所有镜像 [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest 9c6f07244728 13 days ago 5.54MB hello-world latest feb5d9fea6a5 11 months ago 13.3kB [root@centos7 ~]# docker rmi -f `docker images -q` Untagged: alpine:latest Untagged: alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad Deleted: sha256:9c6f0724472873bb50a2ae67a9e7adcb57673a183cea8b06eb778dca859181b5 Deleted: sha256:994393dc58e7931862558d06e46aa2bb17487044f670f310dffe1d24e4d1eec7 Untagged: hello-world:latest Untagged: hello-world@sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625 Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412 Deleted: sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359 [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE
Commands: attach Attach local standard input, output, and error streams to a running container commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem exec Run a command in a running container export Export a container's filesystem as a tar archive inspect Display detailed information on one or more containers kill Kill one or more running containers logs Fetch the logs of a container ls List containers pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container prune Remove all stopped containers rename Rename a container restart Restart one or more containers rm Remove one or more containers run Run a command in a new container start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers wait Block until one or more containers stop, then print their exit codes
Run 'docker container COMMAND --help' for more information on a command.
启动容器
docker run 可以启动容器,进入到容器,并随机生成容器ID和名称
启动第一个容器
[root@centos7 ~]# docker run hello-world
Hello from Docker! This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit: https://docs.docker.com/get-started/
[root@centos7 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 46f601445bd8 hello-world "/hello" 30 seconds ago Exited (0) 29 seconds ago festive_sammet [root@centos7 ~]#
启动容器的流程
启动容器的用法
docker run [选项] [镜像名] [shell命令] [参数] # 选项 -i Keep STDIN open even if not attached,通常和-t一起用 -t 分配 pseudo-TTY,通常和-i一起使用,注意对应容器必须运行shell才支持进入 -d 后台运行,默认前台运行 --name string 容器名称 --h,--hostname string 容器 hostname --rm 容器关闭后自动删除容器 -p list 指定要映射的端口到内部容器开放的端口 -P 随机映射端口到内部容器开放的端口(49000~49900) --dns list 设置DNS --entrypoint string 运行指令 --restart policy -e,--env=[] 设置环境变量 --env-file=[]
docker ps [OPTIONS] docker container ls [OPTIONS] # 选项 -a Show all containers (default shows just running) -q Only display numeric IDs -s Display total file sizes -f Filter output based on conditions provided -l Show the latest created container (includes all states) -n Show n last created containers (includes all states) (default -1)
docker stats [OPTIONS] [CONTAINER...] # 选项 -a,--all Show all containers (default shows just running) --format string Pretty-print images using a Go template --no-stream Disable streaming stats and only pull the first result --no-trunc Do not truncate output
查看容器的详细信息
docker inspect 可以查看docker各种对象的详细信息,包括:镜像,容器,网络等
docker inspect [OPTIONS] NAME|ID [NAME|ID...] # 选项 -f string Format the output using the given Go trmplate -s Display total file sizes if the type is container
删除容器
docker rm 可以删除容器
docker rm [OPTIONS] CONTAINER [CONTAINER...] docker container rm [OPTIONS] CONTAINER [CONTAINER...] # 选项 -f Force the removal of a running container (uses SIGKILL) -v Remove
docker exec [OPTIONS] CONTAINER COMMAND [ARG...] # 常用选项 -d Detached mode:run command in the background -e Set environment variables -i Keep STDIN open even if not attached -t Allocate a psedu-TTY # 常见用法 docker exec -it 容器ID sh|bash
docker logs [OPTIONS] CONTAINER # 选项: --details Show extra details provided to logs -f,--follow Follow log output --since string Show logs since timestamp --tail string Number of lines to show from the end of the logs (default "all") -t,--timestamps Show timestamps --until string Show logs before a timestamp
[root@centos7 ~]# docker run -d alpine fc8dc5bee8367725a759f15417316a619b098af88f1ad7f7113fa314dd6e3f34 [root@centos7 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fc8dc5bee836 alpine "/bin/sh" 6 seconds ago Exited (0) 5 seconds ago exciting_chebyshev [root@centos7 ~]# docker run -d alpine tail -f /etc/hosts 05a4c6863bcc9d7c4b9f0abeec2316a9cce0f0e3f2aeb37bfa57fcd2bcdf8d52 [root@centos7 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 05a4c6863bcc alpine "tail -f /etc/hosts" 2 seconds ago Up 1 second vigilant_lumiere [root@centos7 ~]# docker exec -it 05a sh / # ps aux PID USER TIME COMMAND 1 root 0:00 tail -f /etc/hosts 7 root 0:00 sh 13 root 0:00 ps aux [root@centos7 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 05a4c6863bcc alpine "tail -f /etc/hosts" About a minute ago Up About a minute vigilant_lumiere
容器内部的hosts文件
容器会自动将容器的ID加入自己的/etc/hosts文件中,并解析成容器的IP
[root@centos7 ~]# docker run -it centos /bin/bash [root@8f4c940da642 /]# cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.17.0.3 8f4c940da642 # 默认会将实例的ID 添加到自己的hosts文件 [root@8f4c940da642 /]# hostname 8f4c940da642 [root@8f4c940da642 /]# ping 8f4c940da642 PING 8f4c940da642 (172.17.0.3) 56(84) bytes of data. 64 bytes from 8f4c940da642 (172.17.0.3): icmp_seq=1 ttl=64 time=0.071 ms 64 bytes from 8f4c940da642 (172.17.0.3): icmp_seq=2 ttl=64 time=0.059 ms 64 bytes from 8f4c940da642 (172.17.0.3): icmp_seq=3 ttl=64 time=0.058 ms ^C --- 8f4c940da642 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2005ms rtt min/avg/max/mdev = 0.058/0.062/0.071/0.010 ms # 修改容器的hosts文件 [root@centos7 ~]# docker run -it --rm --add-host chensir.ink:8.8.8.8 --add-host chensir.com:6.6.6.6 busybox / # cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 8.8.8.8 chensir.ink 6.6.6.6 chensir.com 172.17.0.4 4397ad2a1497 / # ping chensir.ink PING chensir.ink (8.8.8.8): 56 data bytes 64 bytes from 8.8.8.8: seq=0 ttl=127 time=70.911 ms 64 bytes from 8.8.8.8: seq=1 ttl=127 time=69.407 ms 64 bytes from 8.8.8.8: seq=2 ttl=127 time=64.564 ms 64 bytes from 8.8.8.8: seq=3 ttl=127 time=69.504 ms ^C --- chensir.ink ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max = 64.564/68.596/70.911 ms / # ping chensir.com PING chensir.com (6.6.6.6): 56 data bytes ^C --- chensir.com ping statistics --- 2 packets transmitted, 0 packets received, 100% packet loss
[root@centos7 ~]# docker run --name mysql01 mysql:5.7.31 WARNING: IPv4 forwarding is disabled. Networking will not work. 2022-08-23 02:08:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started. 2022-08-23 02:08:23+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2022-08-23 02:08:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started. 2022-08-23 02:08:23+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD [root@centos7 ~]# docker run --name mysql-test1 -v /data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wpuser -e MYSQL_PASSWORD=123456 -d -p 3306:3306 mysql:5.7.31 WARNING: IPv4 forwarding is disabled. Networking will not work. ba743ba4068b36c7b2ff804decbb0c5f22aaa8ab0b20ce8bc4c4380ccc990674
# 启动容器 [root@centos7 ~]# docker run -it -p 80 --name nginx_ubuntu ubuntu bash # 查看ubuntu系统信息 root@d35021705364:/# cat /etc/os-release NAME="Ubuntu" VERSION="20.04.3 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.3 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal # 更新源 root@d35021705364:/# apt update Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB] Get:3 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [888 kB] Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:5 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [27.5 kB] Get:6 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [2091 kB] Get:7 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB] Get:8 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB] Get:9 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB] Get:10 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [1462 kB] Get:11 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB] Get:12 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB] Get:13 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1183 kB] Get:14 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [1572 kB] Get:15 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2547 kB] Get:16 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [30.2 kB] Get:17 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [27.4 kB] Get:18 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [55.1 kB] Fetched 23.3 MB in 28s (841 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 34 packages can be upgraded. Run 'apt list --upgradable' to see them. # 安装nginx root@d35021705364:/# apt install -y nginx Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: fontconfig-config fonts-dejavu-core iproute2 libatm1 libbsd0 libcap2 libcap2-bin libelf1 libexpat1 libfontconfig1 libfreetype6 libgd3 libicu66 libjbig0 libjpeg-turbo8 libjpeg8 libmnl0 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libpam-cap libpng16-16 libssl1.1 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2 libxpm4 libxslt1.1 libxtables12 nginx-common nginx-core tzdata ucf Suggested packages: iproute2-doc libgd-tools fcgiwrap nginx-doc ssl-cert The following NEW packages will be installed: fontconfig-config fonts-dejavu-core iproute2 libatm1 libbsd0 libcap2 libcap2-bin libelf1 libexpat1 libfontconfig1 libfreetype6 libgd3 libicu66 libjbig0 libjpeg-turbo8 libjpeg8 libmnl0 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libpam-cap libpng16-16 libssl1.1 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxml2 libxpm4 libxslt1.1 libxtables12 nginx nginx-common nginx-core tzdata ucf 0 upgraded, 40 newly installed, 0 to remove and 34 not upgraded. Need to get 15.8 MB of archives. After this operation, 60.8 MB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 libbsd0 amd64 0.10.0-1 [45.4 kB] Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 libcap2 amd64 1:2.32-1 [15.9 kB] Get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 libelf1 amd64 0.176-1.1build1 [44.0 kB] Get:4 http://archive.ubuntu.com/ubuntu focal/main amd64 libmnl0 amd64 1.0.4-2 [12.3 kB] Get:5 http://archive.ubuntu.com/ubuntu focal/main amd64 libxtables12 amd64 1.8.4-3ubuntu2 [28.4 kB] Get:6 http://archive.ubuntu.com/ubuntu focal/main amd64 libcap2-bin amd64 1:2.32-1 [26.2 kB] Get:7 http://archive.ubuntu.com/ubuntu focal/main amd64 iproute2 amd64 5.5.0-1ubuntu1 [858 kB] Get:8 http://archive.ubuntu.com/ubuntu focal/main amd64 libatm1 amd64 1:2.5.1-4 [21.8 kB] Get:9 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libexpat1 amd64 2.2.9-1ubuntu0.4 [74.4 kB] Get:10 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 tzdata all 2022a-0ubuntu0.20.04 [294 kB] Get:11 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libicu66 amd64 66.1-2ubuntu2.1 [8515 kB] Get:12 http://archive.ubuntu.com/ubuntu focal/main amd64 libpam-cap amd64 1:2.32-1 [8352 B] Get:13 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libssl1.1 amd64 1.1.1f-1ubuntu2.16 [1321 kB] Get:14 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libxml2 amd64 2.9.10+dfsg-5ubuntu0.20.04.4 [640 kB] Get:15 http://archive.ubuntu.com/ubuntu focal/main amd64 ucf all 3.0038+nmu1 [51.6 kB] Get:16 http://archive.ubuntu.com/ubuntu focal/main amd64 libpng16-16 amd64 1.6.37-2 [179 kB] Get:17 http://archive.ubuntu.com/ubuntu focal/main amd64 libxau6 amd64 1:1.0.9-0ubuntu1 [7488 B] Get:18 http://archive.ubuntu.com/ubuntu focal/main amd64 libxdmcp6 amd64 1:1.1.3-0ubuntu1 [10.6 kB] Get:19 http://archive.ubuntu.com/ubuntu focal/main amd64 libxcb1 amd64 1.14-2 [44.7 kB] Get:20 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libx11-data all 2:1.6.9-2ubuntu1.2 [113 kB] Get:21 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libx11-6 amd64 2:1.6.9-2ubuntu1.2 [575 kB] Get:22 http://archive.ubuntu.com/ubuntu focal/main amd64 fonts-dejavu-core all 2.37-1 [1041 kB] Get:23 http://archive.ubuntu.com/ubuntu focal/main amd64 fontconfig-config all 2.13.1-2ubuntu3 [28.8 kB] Get:24 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libfreetype6 amd64 2.10.1-2ubuntu0.2 [341 kB] Get:25 http://archive.ubuntu.com/ubuntu focal/main amd64 libfontconfig1 amd64 2.13.1-2ubuntu3 [114 kB] Get:26 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libjpeg-turbo8 amd64 2.0.3-0ubuntu1.20.04.1 [117 kB] Get:27 http://archive.ubuntu.com/ubuntu focal/main amd64 libjpeg8 amd64 8c-2ubuntu8 [2194 B] Get:28 http://archive.ubuntu.com/ubuntu focal/main amd64 libjbig0 amd64 2.1-3.1build1 [26.7 kB] Get:29 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libwebp6 amd64 0.6.1-2ubuntu0.20.04.1 [185 kB] Get:30 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libtiff5 amd64 4.1.0+git191117-2ubuntu0.20.04.3 [162 kB] Get:31 http://archive.ubuntu.com/ubuntu focal/main amd64 libxpm4 amd64 1:3.5.12-1 [34.0 kB] Get:32 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libgd3 amd64 2.2.5-5.2ubuntu2.1 [118 kB] Get:33 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 nginx-common all 1.18.0-0ubuntu1.3 [37.7 kB] Get:34 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libnginx-mod-http-image-filter amd64 1.18.0-0ubuntu1.3 [14.8 kB] Get:35 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libxslt1.1 amd64 1.1.34-4ubuntu0.20.04.1 [151 kB] Get:36 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libnginx-mod-http-xslt-filter amd64 1.18.0-0ubuntu1.3 [13.0 kB] Get:37 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libnginx-mod-mail amd64 1.18.0-0ubuntu1.3 [42.8 kB] Get:38 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libnginx-mod-stream amd64 1.18.0-0ubuntu1.3 [67.3 kB] Get:39 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 nginx-core amd64 1.18.0-0ubuntu1.3 [425 kB] Get:40 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 nginx all 1.18.0-0ubuntu1.3 [3620 B] Fetched 15.8 MB in 9s (1680 kB/s) debconf: delaying package configuration, since apt-utils is not installed Selecting previously unselected package libbsd0:amd64. (Reading database ... 4127 files and directories currently installed.) Preparing to unpack .../00-libbsd0_0.10.0-1_amd64.deb ... Unpacking libbsd0:amd64 (0.10.0-1) ... Selecting previously unselected package libcap2:amd64. Preparing to unpack .../01-libcap2_1%3a2.32-1_amd64.deb ... Unpacking libcap2:amd64 (1:2.32-1) ... Selecting previously unselected package libelf1:amd64. Preparing to unpack .../02-libelf1_0.176-1.1build1_amd64.deb ... Unpacking libelf1:amd64 (0.176-1.1build1) ... Selecting previously unselected package libmnl0:amd64. Preparing to unpack .../03-libmnl0_1.0.4-2_amd64.deb ... Unpacking libmnl0:amd64 (1.0.4-2) ... Selecting previously unselected package libxtables12:amd64. Preparing to unpack .../04-libxtables12_1.8.4-3ubuntu2_amd64.deb ... Unpacking libxtables12:amd64 (1.8.4-3ubuntu2) ... Selecting previously unselected package libcap2-bin. Preparing to unpack .../05-libcap2-bin_1%3a2.32-1_amd64.deb ... Unpacking libcap2-bin (1:2.32-1) ... Selecting previously unselected package iproute2. Preparing to unpack .../06-iproute2_5.5.0-1ubuntu1_amd64.deb ... Unpacking iproute2 (5.5.0-1ubuntu1) ... Selecting previously unselected package libatm1:amd64. Preparing to unpack .../07-libatm1_1%3a2.5.1-4_amd64.deb ... Unpacking libatm1:amd64 (1:2.5.1-4) ... Selecting previously unselected package libexpat1:amd64. Preparing to unpack .../08-libexpat1_2.2.9-1ubuntu0.4_amd64.deb ... Unpacking libexpat1:amd64 (2.2.9-1ubuntu0.4) ... Selecting previously unselected package tzdata. Preparing to unpack .../09-tzdata_2022a-0ubuntu0.20.04_all.deb ... Unpacking tzdata (2022a-0ubuntu0.20.04) ... Selecting previously unselected package libicu66:amd64. Preparing to unpack .../10-libicu66_66.1-2ubuntu2.1_amd64.deb ... Unpacking libicu66:amd64 (66.1-2ubuntu2.1) ... Selecting previously unselected package libpam-cap:amd64. Preparing to unpack .../11-libpam-cap_1%3a2.32-1_amd64.deb ... Unpacking libpam-cap:amd64 (1:2.32-1) ... Selecting previously unselected package libssl1.1:amd64. Preparing to unpack .../12-libssl1.1_1.1.1f-1ubuntu2.16_amd64.deb ... Unpacking libssl1.1:amd64 (1.1.1f-1ubuntu2.16) ... Selecting previously unselected package libxml2:amd64. Preparing to unpack .../13-libxml2_2.9.10+dfsg-5ubuntu0.20.04.4_amd64.deb ... Unpacking libxml2:amd64 (2.9.10+dfsg-5ubuntu0.20.04.4) ... Selecting previously unselected package ucf. Preparing to unpack .../14-ucf_3.0038+nmu1_all.deb ... Moving old data out of the way Unpacking ucf (3.0038+nmu1) ... Selecting previously unselected package libpng16-16:amd64. Preparing to unpack .../15-libpng16-16_1.6.37-2_amd64.deb ... Unpacking libpng16-16:amd64 (1.6.37-2) ... Selecting previously unselected package libxau6:amd64. Preparing to unpack .../16-libxau6_1%3a1.0.9-0ubuntu1_amd64.deb ... Unpacking libxau6:amd64 (1:1.0.9-0ubuntu1) ... Selecting previously unselected package libxdmcp6:amd64. Preparing to unpack .../17-libxdmcp6_1%3a1.1.3-0ubuntu1_amd64.deb ... Unpacking libxdmcp6:amd64 (1:1.1.3-0ubuntu1) ... Selecting previously unselected package libxcb1:amd64. Preparing to unpack .../18-libxcb1_1.14-2_amd64.deb ... Unpacking libxcb1:amd64 (1.14-2) ... Selecting previously unselected package libx11-data. Preparing to unpack .../19-libx11-data_2%3a1.6.9-2ubuntu1.2_all.deb ... Unpacking libx11-data (2:1.6.9-2ubuntu1.2) ... Selecting previously unselected package libx11-6:amd64. Preparing to unpack .../20-libx11-6_2%3a1.6.9-2ubuntu1.2_amd64.deb ... Unpacking libx11-6:amd64 (2:1.6.9-2ubuntu1.2) ... Selecting previously unselected package fonts-dejavu-core. Preparing to unpack .../21-fonts-dejavu-core_2.37-1_all.deb ... Unpacking fonts-dejavu-core (2.37-1) ... Selecting previously unselected package fontconfig-config. Preparing to unpack .../22-fontconfig-config_2.13.1-2ubuntu3_all.deb ... Unpacking fontconfig-config (2.13.1-2ubuntu3) ... Selecting previously unselected package libfreetype6:amd64. Preparing to unpack .../23-libfreetype6_2.10.1-2ubuntu0.2_amd64.deb ... Unpacking libfreetype6:amd64 (2.10.1-2ubuntu0.2) ... Selecting previously unselected package libfontconfig1:amd64. Preparing to unpack .../24-libfontconfig1_2.13.1-2ubuntu3_amd64.deb ... Unpacking libfontconfig1:amd64 (2.13.1-2ubuntu3) ... Selecting previously unselected package libjpeg-turbo8:amd64. Preparing to unpack .../25-libjpeg-turbo8_2.0.3-0ubuntu1.20.04.1_amd64.deb ... Unpacking libjpeg-turbo8:amd64 (2.0.3-0ubuntu1.20.04.1) ... Selecting previously unselected package libjpeg8:amd64. Preparing to unpack .../26-libjpeg8_8c-2ubuntu8_amd64.deb ... Unpacking libjpeg8:amd64 (8c-2ubuntu8) ... Selecting previously unselected package libjbig0:amd64. Preparing to unpack .../27-libjbig0_2.1-3.1build1_amd64.deb ... Unpacking libjbig0:amd64 (2.1-3.1build1) ... Selecting previously unselected package libwebp6:amd64. Preparing to unpack .../28-libwebp6_0.6.1-2ubuntu0.20.04.1_amd64.deb ... Unpacking libwebp6:amd64 (0.6.1-2ubuntu0.20.04.1) ... Selecting previously unselected package libtiff5:amd64. Preparing to unpack .../29-libtiff5_4.1.0+git191117-2ubuntu0.20.04.3_amd64.deb ... Unpacking libtiff5:amd64 (4.1.0+git191117-2ubuntu0.20.04.3) ... Selecting previously unselected package libxpm4:amd64. Preparing to unpack .../30-libxpm4_1%3a3.5.12-1_amd64.deb ... Unpacking libxpm4:amd64 (1:3.5.12-1) ... Selecting previously unselected package libgd3:amd64. Preparing to unpack .../31-libgd3_2.2.5-5.2ubuntu2.1_amd64.deb ... Unpacking libgd3:amd64 (2.2.5-5.2ubuntu2.1) ... Selecting previously unselected package nginx-common. Preparing to unpack .../32-nginx-common_1.18.0-0ubuntu1.3_all.deb ... Unpacking nginx-common (1.18.0-0ubuntu1.3) ... Selecting previously unselected package libnginx-mod-http-image-filter. Preparing to unpack .../33-libnginx-mod-http-image-filter_1.18.0-0ubuntu1.3_amd64.deb ... Unpacking libnginx-mod-http-image-filter (1.18.0-0ubuntu1.3) ... Selecting previously unselected package libxslt1.1:amd64. Preparing to unpack .../34-libxslt1.1_1.1.34-4ubuntu0.20.04.1_amd64.deb ... Unpacking libxslt1.1:amd64 (1.1.34-4ubuntu0.20.04.1) ... Selecting previously unselected package libnginx-mod-http-xslt-filter. Preparing to unpack .../35-libnginx-mod-http-xslt-filter_1.18.0-0ubuntu1.3_amd64.deb ... Unpacking libnginx-mod-http-xslt-filter (1.18.0-0ubuntu1.3) ... Selecting previously unselected package libnginx-mod-mail. Preparing to unpack .../36-libnginx-mod-mail_1.18.0-0ubuntu1.3_amd64.deb ... Unpacking libnginx-mod-mail (1.18.0-0ubuntu1.3) ... Selecting previously unselected package libnginx-mod-stream. Preparing to unpack .../37-libnginx-mod-stream_1.18.0-0ubuntu1.3_amd64.deb ... Unpacking libnginx-mod-stream (1.18.0-0ubuntu1.3) ... Selecting previously unselected package nginx-core. Preparing to unpack .../38-nginx-core_1.18.0-0ubuntu1.3_amd64.deb ... Unpacking nginx-core (1.18.0-0ubuntu1.3) ... Selecting previously unselected package nginx. Preparing to unpack .../39-nginx_1.18.0-0ubuntu1.3_all.deb ... Unpacking nginx (1.18.0-0ubuntu1.3) ... Setting up libexpat1:amd64 (2.2.9-1ubuntu0.4) ... Setting up libxau6:amd64 (1:1.0.9-0ubuntu1) ... Setting up libssl1.1:amd64 (1.1.1f-1ubuntu2.16) ... debconf: unable to initialize frontend: Dialog debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.) debconf: falling back to frontend: Readline debconf: unable to initialize frontend: Readline debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.) debconf: falling back to frontend: Teletype Setting up nginx-common (1.18.0-0ubuntu1.3) ... debconf: unable to initialize frontend: Dialog debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.) debconf: falling back to frontend: Readline debconf: unable to initialize frontend: Readline debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.) debconf: falling back to frontend: Teletype Setting up libatm1:amd64 (1:2.5.1-4) ... Setting up libjbig0:amd64 (2.1-3.1build1) ... Setting up libcap2:amd64 (1:2.32-1) ... Setting up tzdata (2022a-0ubuntu0.20.04) ... debconf: unable to initialize frontend: Dialog debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.) debconf: falling back to frontend: Readline debconf: unable to initialize frontend: Readline debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.) debconf: falling back to frontend: Teletype Configuring tzdata ------------------
Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities, representing the time zones in which they are located.
1. Africa 3. Antarctica 5. Arctic 7. Atlantic 9. Indian 11. SystemV 13. Etc 2. America 4. Australia 6. Asia 8. Europe 10. Pacific 12. US Geographic area: 6
Please select the city or region corresponding to your time zone.
Current default time zone: 'Asia/Shanghai' Local time is now: Wed Aug 24 15:05:46 CST 2022. Universal Time is now: Wed Aug 24 07:05:46 UTC 2022. Run 'dpkg-reconfigure tzdata' if you wish to change it.
Setting up libcap2-bin (1:2.32-1) ... Setting up libx11-data (2:1.6.9-2ubuntu1.2) ... Setting up libpng16-16:amd64 (1.6.37-2) ... Setting up libmnl0:amd64 (1.0.4-2) ... Setting up libwebp6:amd64 (0.6.1-2ubuntu0.20.04.1) ... Setting up fonts-dejavu-core (2.37-1) ... Setting up ucf (3.0038+nmu1) ... debconf: unable to initialize frontend: Dialog debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.) debconf: falling back to frontend: Readline debconf: unable to initialize frontend: Readline debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.) debconf: falling back to frontend: Teletype Setting up libjpeg-turbo8:amd64 (2.0.3-0ubuntu1.20.04.1) ... Setting up libxtables12:amd64 (1.8.4-3ubuntu2) ... Setting up libbsd0:amd64 (0.10.0-1) ... Setting up libelf1:amd64 (0.176-1.1build1) ... Setting up libpam-cap:amd64 (1:2.32-1) ... debconf: unable to initialize frontend: Dialog debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.) debconf: falling back to frontend: Readline debconf: unable to initialize frontend: Readline debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.) debconf: falling back to frontend: Teletype Setting up libjpeg8:amd64 (8c-2ubuntu8) ... Setting up libnginx-mod-mail (1.18.0-0ubuntu1.3) ... Setting up libxdmcp6:amd64 (1:1.1.3-0ubuntu1) ... Setting up libxcb1:amd64 (1.14-2) ... Setting up fontconfig-config (2.13.1-2ubuntu3) ... Setting up iproute2 (5.5.0-1ubuntu1) ... debconf: unable to initialize frontend: Dialog debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.) debconf: falling back to frontend: Readline debconf: unable to initialize frontend: Readline debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.) debconf: falling back to frontend: Teletype Setting up libicu66:amd64 (66.1-2ubuntu2.1) ... Setting up libnginx-mod-stream (1.18.0-0ubuntu1.3) ... Setting up libfreetype6:amd64 (2.10.1-2ubuntu0.2) ... Setting up libx11-6:amd64 (2:1.6.9-2ubuntu1.2) ... Setting up libtiff5:amd64 (4.1.0+git191117-2ubuntu0.20.04.3) ... Setting up libfontconfig1:amd64 (2.13.1-2ubuntu3) ... Setting up libxml2:amd64 (2.9.10+dfsg-5ubuntu0.20.04.4) ... Setting up libxpm4:amd64 (1:3.5.12-1) ... Setting up libgd3:amd64 (2.2.5-5.2ubuntu2.1) ... Setting up libxslt1.1:amd64 (1.1.34-4ubuntu0.20.04.1) ... Setting up libnginx-mod-http-image-filter (1.18.0-0ubuntu1.3) ... Setting up libnginx-mod-http-xslt-filter (1.18.0-0ubuntu1.3) ... Setting up nginx-core (1.18.0-0ubuntu1.3) ... invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start. Setting up nginx (1.18.0-0ubuntu1.3) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ... # 查看nginx版本 root@d35021705364:/# nginx -v nginx version: nginx/1.18.0 (Ubuntu) root@d35021705364:/# grep include /etc/nginx/nginx.conf include /etc/nginx/modules-enabled/*.conf; include /etc/nginx/mime.types; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; root@d35021705364:/# grep root /etc/nginx/sites-enabled/default root /var/www/html; # deny access to .htaccess files, if Apache's document root # root /var/www/example.com; root@d35021705364:/# echo Nginx website in Docker > /var/www/html/index.html root@d35021705364:/# exit exit # 提交为镜像 [root@centos7 ~]# docker commit -a 'chensir' -m 'nginx-ubuntu:20.04' nginx_ubuntu nginx_ubuntu20.04:v1.18.0 sha256:b33b57cff5d3c68c56b5826490ddcb0c9e7751f2d275a9d6d1e43d63764f78b0 [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx_ubuntu20.04 v1.18.0 b33b57cff5d3 5 seconds ago 169MB # 从制作的新镜像启动容器并测试访问 [root@centos7 ~]# docker run -d -p 80 --name nginx-web nginx_ubuntu20.04:v1.18.0 nginx -g 'daemon off;' 06098c8bc2ec93978167950adfa5e827c75174aba306337165813a9e950b1972 [root@centos7 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 06098c8bc2ec nginx_ubuntu20.04:v1.18.0 "nginx -g 'daemon of…" 2 seconds ago Up 2 seconds 0.0.0.0:49162->80/tcp, :::49162->80/tcp nginx-web [root@centos7 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 06098c8bc2ec nginx_ubuntu20.04:v1.18.0 "nginx -g 'daemon of…" 2 seconds ago Up 2 seconds 0.0.0.0:49162->80/tcp, :::49162->80/tcp nginx-web [root@centos7 ~]# docker port nginx-web 80/tcp -> 0.0.0.0:49162 80/tcp -> :::49162 [root@centos7 ~]# curl 127.0.0.1:49162 Nginx website in Docker
基于CentOS的基础镜像利用yum安装手动制作nginx的镜像
[root@centos7 ~]# docker pull centos:centos7.7.1908 centos7.7.1908: Pulling from library/centos f34b00c7da20: Pull complete Digest: sha256:50752af5182c6cd5518e3e91d48f7ff0cba93d5d760a67ac140e2d63c4dd9efc Status: Downloaded newer image for centos:centos7.7.1908 docker.io/library/centos:centos7.7.1908 [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos centos7.7.1908 08d05d1d5859 2 years ago 204MB [root@centos7 ~]# docker run -it centos:centos7.7.1908 bash # 修改时区 [root@0b3db04f3a72 /]# rm -f /etc/localtime [root@0b3db04f3a72 /]# ln -s ../usr/share/zoneinfo/Asia/Shanghai /etc/localtime # 更改yum源 [root@0b3db04f3a72 /]# yum install -y wget [root@0b3db04f3a72 /]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo [root@0b3db04f3a72 /]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo [root@0b3db04f3a72 /]# yum install -y nginx # 安装相关软件和工具 # yum 安装 nginx [root@0b3db04f3a72 /]# yum install -y nginx # 安装常用命令 [root@0b3db04f3a72 /]# yum install -y vim curl iproute net-tools # 清理yum缓存 [root@0b3db04f3a72 /]# rm -rf /var/cache/yum/* # 修改服务的配置信息关闭服务后台运行 # 关闭nginx后台运行 [root@0b3db04f3a72 /]# vim /etc/nginx/nginx.conf user nginx; daemon off; # 关闭后台运行 # 准备程序和数据 # 自定义web界面 [root@0b3db04f3a72 /]# rm -rf /usr/share/nginx/html/index.html [root@0b3db04f3a72 /]# echo "Nginx Page in Docker" > /usr/share/nginx/html/index.html # 提交为镜像 # docker commit命令在宿主机基于容器ID提交为镜像 [root@centos7 ~]# docker commit -a "chensir" -m "nginx yum v1" -c "EXPOSE 80 443" 0b3db04f3a72 chensir/centos-nginx:1.16.1.v1 sha256:3f649568eaca282c2ff0864d725bb0310862849e9393abfb14f49fa60d7071f7 [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE chensir/centos-nginx 1.16.1.v1 3f649568eaca 17 seconds ago 322MB centos centos7.7.1908 08d05d1d5859 2 years ago 204MB # 从制作的镜像启动容器 [root@centos7 ~]# docker run -d -p 8080:80 --name my-centos-nginx chensir/centos-nginx:1.16.1.v1 /usr/sbin/nginx df983ecee256956f34af0ca6089331bd9bd1863ad24d35defef05c86e6cab5f2 [root@centos7 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES df983ecee256 chensir/centos-nginx:1.16.1.v1 "/usr/sbin/nginx" 5 seconds ago Up 5 seconds 443/tcp, 0.0.0.0:8080->80/tcp, :::8080->80/tcp my-centos-nginx # 访问测试镜像 [root@centos7 ~]# curl 127.0.0.1:8080 Nginx Page in Docker
FROM [--platform=<platform>] <image> [AS <name>] FROM [--platform=<platform>] <image>[:<tag>] [AS <name>] FROM [--platform=<platform>] <image>[@<digest>] [AS <name>] # 说明: --platform 指定镜像的平台,比如:linux/amd64,linux/arm64,or windows/amd64 tag 和 digest是可选项,如果不指定,默认为latest
说明:关于scrach镜像
FROM scratch # 所有镜像的起源镜像,相当于object类 参考链接: https://hub.docker.com/_/scratch?tab=description https://docs.docker.com/develop/develop-images/baseimages/ 该镜像是一个空的镜像,可以用于构建busybox等超小镜像,可以说是真正的从零开始构建属于自己的镜像 该镜像在构建基础镜像(例如Debian和busybox)或超最小镜像(仅包含一个二进制文件及其所需内容,例如:hello-world)的上下文中最有用。 # 示例 FROM ubuntu FROM ubuntu:bionic FROM debian:buster-slim
LABEL:指定镜像元数据
可以指定镜像元数据,如:镜像作者等
LABEL <key>=<value> <key>=<value> <key>:<value>... # 示例 LABEL "com.example.vendor"="ACME Incorporated" LABEL com.example.label-with-value="foo" LABEL version="1.0" LABEL description="This text illustrates that label-values can span multiple lines"
docker run -e | --env <key>=<value> # 说明 -e,--env list # Set environment variables --env-file filename # Read in a file of environment variables # 示例:两种格式功能相同 # 格式1 ENV myName="John Doe" myDog=Rex\ The\ Dog myCat=fluffy # 格式2 ENV myName John Doe ENV myDog Rex The Dog ENV myCat fluffy
[root@centos7 ~]# cat Dockerfile FROM busybox LABEL maintainer="chensir <root@chensir.ink>" ENV NAME zhao xing chen RUN touch $NAME.txt
WORKDIR /path/to/workdir # 示例 # 两次 RUN 独立运行,不在同一个目录 RUN cd /app RUN echo "hello" > world.txt # 如果想实现相同目录可以使用 WORKDIR WORKDIR /app RUN echo "hello" > world.txt # 可以使用多个WORKDIR指令,后续命令如果参数是相对路径,则会基于之前命令指定的路径 WORKDIR /a WORKDIR b WORKDIR c RUN pwd # 最终路径为 /a/b/c
docker run --name <容器名称> docker run -d --name 容器名称 --link <目标容器名称>:<容器别名> docker run -d --name 容器名称 --link <目标容器名称>:"<容器别名> <容器别名> <容器别名>" # 可以是多个别名
Docker网络连接模式
Docker网络支持5种网络模式:
none
bridge
host
container
network-name
# 查看默认的网络模式 [root@centos7 ~]# docker network ls NETWORK ID NAME DRIVER SCOPE adaac389304f bridge bridge local 5feb362eb28e host host local 00f34cf82248 none null local
网络模式指定
# 默认新建的容器使用Bridge模式,创建容器时,docker run 命令使用以下指定网络模式 docker run --network <model> docker run --net=<mode>
Commands: connect Connect a container to a network create Create a network disconnect Disconnect a container from a network inspect Display detailed information on one or more networks ls List networks prune Remove all unused networks rm Remove one or more networks
Run 'docker network COMMAND --help' for more information on a command. # 创建自定义网络 注意mode不支持host和none docker network create -d <mode> --subnet <CIDR> --gateway <网关> <自定义网络名称> # 查看自定义网络 docker network inspect <自定义网络名称或网络ID> # 引用自定义网络 docker run --network <自定义网络名称> <镜像名称> # 删除自定义网络 docker network rm <自定义网络名称或网络ID>
[root@centos7 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f2373f9e7c67 registry:2.7.1 "/entrypoint.sh /etc…" 47 seconds ago Up 46 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp registry [root@centos7 ~]# docker port f23 5000/tcp -> 0.0.0.0:5000 5000/tcp -> :::5000 # 登陆仓库 # docker login 默认使用https登录,而docker registry为http,所以默认登录失败 [root@centos7 ~]# docker login 10.0.0.14:5000 Username: chensir Password: Error response from daemon: Get "https://10.0.0.14:5000/v2/": http: server gave HTTP response to HTTPS client # 修改配置使docker login支持HTTP协议 [root@centos7 ~]# vim /lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry 10.0.0.14:5000 [root@centos7 ~]# systemctl daemon-reload [root@centos7 ~]# systemctl restart docker # 再次登录 验证成功 [root@centos7 ~]# docker login 10.0.0.14:5000 Authenticating with existing credentials... WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded # 打包并上传镜像 [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE test v1 401a15cbac90 8 days ago 1.24MB [root@centos7 ~]# docker tag test:v1 10.0.0.14:5000/test:v1 [root@centos7 ~]# docker push 10.0.0.14:5000/test:v1 The push refers to repository [10.0.0.14:5000/test] 084326605ab6: Pushed v1: digest: sha256:c04ecf7d8a544273ae7b7d1cda2f6c123a9690fc56c705dd5e16a20c65bba555 size: 527 # 下载镜像 [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry 2.7.1 b8604a3fe854 9 months ago 26.2MB [root@centos7 ~]# docker pull 10.0.0.14:5000/test:v1 v1: Pulling from test 50783e0dfb64: Pull complete Digest: sha256:c04ecf7d8a544273ae7b7d1cda2f6c123a9690fc56c705dd5e16a20c65bba555 Status: Downloaded newer image for 10.0.0.14:5000/test:v1 10.0.0.14:5000/test:v1 [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.14:5000/test v1 401a15cbac90 8 days ago 1.24MB registry 2.7.1 b8604a3fe854 9 months ago 26.2MB
# 修改images的名称,不修改成指定格式无法将镜像上传到harbor仓库 # 格式为 (项目名需要登录Harbor管理页面去新建 如果不事先建立项目,上传镜像失败) Harbor主机IP/项目名/image名字:版本 # 例如 [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE busybox-chensir v1.0 71a52e0618a5 3 seconds ago 1.24MB [root@centos7 ~]# docker login 10.0.0.16 Authenticating with existing credentials... WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded [root@centos7 ~]# docker tag busybox-chensir:v1.0 10.0.0.16/chensir/busybox-chensir:v1.0 [root@centos7 ~]# docker push 10.0.0.16/chensir/busybox-chensir:v1.0 The push refers to repository [10.0.0.16/chensir/busybox-chensir] c1cf1676e7d0: Pushed v1.0: digest: sha256:c501ccda169599fb77102ad0c2e2568336eaccf9ad83c94aec0d6f28fb55c0a0 size: 527
下载harbor镜像
在10.0.0.15的centos7主机上无需登录,即可下载镜像
注:下载前需修改docker的service文件,加入harbor服务器的地址才可以下载
[root@centos7 ~]# docker pull 10.0.0.16/chensir/busybox-chensir:v1.0 Error response from daemon: Get "https://10.0.0.16/v2/": dial tcp 10.0.0.16:443: connect: connection refused [root@centos7 ~]# vim /lib/systemd/system/docker.service [root@centos7 ~]# systemctl daemon-reload [root@centos7 ~]# systemctl restart docker [root@centos7 ~]# docker pull 10.0.0.16/chensir/busybox-chensir:v1.0 v1.0: Pulling from chensir/busybox-chensir 2c39bef88607: Pull complete Digest: sha256:c501ccda169599fb77102ad0c2e2568336eaccf9ad83c94aec0d6f28fb55c0a0 Status: Downloaded newer image for 10.0.0.16/chensir/busybox-chensir:v1.0 10.0.0.16/chensir/busybox-chensir:v1.0 [root@centos7 ~]# vim /lib/systemd/system/docker.service [root@centos7 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 10.0.0.16/chensir/busybox-chensir v1.0 71a52e0618a5 2 hours ago 1.24MB
0 directories, 6 files # 修改配置文件 [root@centos7 certs]# vim /apps/harbor/harbor.yml # https related config https: # https port for harbor, default is 443 port: 443 # The path of cert and key files for nginx certificate: /apps/harbor/certs/harbor.chensir.ink.crt private_key: /apps/harbor/certs/harbor.chensir.ink.key # 更新配置 [root@centos7 harbor]# /apps/harbor/prepare # 启动harbor [root@centos7 harbor]# docker-compose start
在客户端下载CA的证书
# 直接登录和上传下载镜像会报错 [root@centos7 ~]# vim /etc/hosts 10.0.0.16 harbor.chensir.ink [root@centos7 ~]# docker login harbor.chensir.ink Username: admin Password: Error response from daemon: Get "https://harbor.chensir.ink/v2/": x509: certificate has expired or is not yet valid: current time 2022-09-08T13:41:28+08:00 is before 2022-09-08T06:20:55Z # 在客户端下载CA证书 [root@centos7 ~]# mkdir -pv /etc/docker/certs.d/harbor.chensir.org/ [root@centos7 ~]# scp -r harbor.chensir.ink:/apps/harbor/certs/ca.crt /etc/docker/certs.d/harbor.chensir.org/ [root@centos7 ~]# tree /etc/docker/certs.d/ /etc/docker/certs.d/ └── harbor.chensir.org └── ca.crt