When you use docker, you are creating and using images, containers, networks, volumes, pluginns, and other objects.(当你使用 docker 时,你正在创建和使用镜像、容器、网络、卷、插件和其他对象)
IMAGES (镜像)
An image is a read-only template with instructions for creating a docker container.(镜像是一个只读模板,它带有创建 docker 容器的指令。)
Often, an image is based on another image, with some additional customization.(通常,一个镜像基于另一个镜像,并带有一些额外的自定义。)
You might create your own images or you might only use those created by others and published in a registry.(您可以创建自己的镜像,也可以使用其他人创建并在仓库中发布的镜像。)
CONTAINERS (容器)
A conntainer is a runnable instance of an image.(容器是镜像的可运行实例。)
You can create, run, stop, move, or delete a container using the docker API or CLI.(您可以通过 docker API 或 CLI 创建、运行、停止、移动或删除容器。)
You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.(您可以将容器连接到一个或多个网络,为其附加存储,甚至可以根据其当前状态创建新镜像。)
[root@Docker ~]# docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 15893 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2098 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 819 [OK] jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 285 linuxserver/nginx An Nginx container, brought to you by LinuxS… 160 tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 146 [OK] jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 144 [OK] alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 110 [OK] nginxdemos/hello NGINX webserver that serves a simple page co… 79 [OK] privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 60 [OK] nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 57 nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 54 nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 28 staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 25 [OK] nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 22 schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK] centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 16 centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13 flashspys/nginx-static Super Lightweight Nginx Image 11 [OK] bitwarden/nginx The Bitwarden nginx web server acting as a r… 11 mailu/nginx Mailu nginx frontend 9 [OK] sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK] ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 3 [OK] arnau/nginx-gate Docker image with Nginx with Lua enabled on … 1 [OK] wodby/nginx Generic nginx 1 [OK]
[root@Docker ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 57 minutes ago Exited (0) 6 minutes ago youthful_euclid
[root@Docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE httpd latest ad17c88403e2 12 days ago 143MB nginx latest ea335eea17ab 13 days ago 141MB
[root@Docker ~]# docker rmi ad17c88403e2 Untagged: httpd:latest Untagged: httpd@sha256:1d71eef54c08435c0be99877c408637f03112dc9f929fba3cccdd15896099b02 Deleted: sha256:ad17c88403e2cedd27963b98be7f04bd3f903dfa7490586de397d0404424936d Deleted: sha256:a59e7dfeeb485a8a45b1fcce812b10fbd955d304fa2e9ca43b10b16a8ee1afb8 Deleted: sha256:9592080464aa1890ed187c42a13ecc9f175e975a96a3fad28df0559ad0c08b9d Deleted: sha256:42d2debfa0c419f7f89affa3e9b62d1b7e54dc6654dbd186d4654ee3661c44c8 Deleted: sha256:136822c50a75392f4ce06461fa4894aa7d1e060ec0dd4782e13e2d9829df50a3 [root@Docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest ea335eea17ab 13 days ago 141MB
[root@Docker ~]# docker ps //查看正在运行的容器 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Docker ~]# docker ps -a //查看所有容器 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 3 minutes ago Created youthful_euclid
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 8 minutes ago Up 14 seconds 80/tcp youthful_euclid
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 50 minutes ago Up 30 seconds 80/tcp youthful_euclid
[root@Docker ~]# docker attach 8442117bc0c7
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 26 minutes ago Up 3 seconds 80/tcp youthful_euclid
[root@Docker ~]# docker exec -it 8442117bc0c7 /bin/bash root@8442117bc0c7:/# ls bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@8442117bc0c7:/# exit exit
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 27 minutes ago Up 23 seconds 80/tcp youthful_euclid
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 16 minutes ago Up 8 minutes 80/tcp youthful_euclid
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Docker ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 16 minutes ago Exited (0) 5 seconds ago youthful_euclid
[root@Docker ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 17 minutes ago Exited (0) 46 seconds ago youthful_euclid
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 17 minutes ago Up 3 seconds 80/tcp youthful_euclid
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 20 minutes ago Up 2 minutes 80/tcp youthful_euclid
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Docker ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 20 minutes ago Exited (137) 4 seconds ago youthful_euclid
[root@Docker ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 35 minutes ago Exited (0) 5 minutes ago youthful_euclid
[root@Docker ~]# docker run -it httpd /bin/bash #此命令的作用是,拉取一个httpd的镜像,然后创建容器并运行,-it表示以交互的方式进入终端,/bin/bash表示终端的环境 Unable to find image 'httpd:latest' locally latest: Pulling from library/httpd eff15d958d66: Already exists ba1caf8ba86c: Pull complete ab86dc02235d: Pull complete 0d58b11d2867: Pull complete e88da7cb925c: Pull complete Digest: sha256:1d71eef54c08435c0be99877c408637f03112dc9f929fba3cccdd15896099b02 Status: Downloaded newer image for httpd:latest root@a01b8d80a160:/usr/local/apache2# ls bin build cgi-bin conf error htdocs icons include logs modules
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a01b8d80a160 httpd "/bin/bash" 10 minutes ago Up 3 seconds 80/tcp hardcore_varahamihira
[root@Docker ~]# docker rm a01b8d80a160 Error response from daemon: You cannot remove a running container a01b8d80a1609e81d8d8121b3fc3c0f53a676340b3b093b353a7f9bb498fe0e6. Stop the container before attempting removal or force remove
[root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Docker ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8442117bc0c7 nginx "/docker-entrypoint.…" 48 minutes ago Exited (0) 18 minutes ago youthful_euclid