Docker 技术是基于 LXC(Linux container- Linux 容器)虚拟容器技术的。
LXC,其名称来自 Linux 软件容器(Linux Containers)的缩写,一种操作系统层虚拟化(Operating system–level virtualization)技术,为 Linux 内核容器功能的一个用户空间接口。它将应用软件系统打包成一个软件容器(Container),内含应用软件本身的代码,以及所需要的操作系统核心和库。通过统一的名字空间和共用 API 来分配不同软件容器的可用硬件资源,创造出应用程序的独立沙箱运行环境,使得 Linux 用户可以容易的创建和管理系统或应用容器。
LXC 技术主要是借助 Linux 内核中提供的 CGroup 功能和 name space 来实现的,通过 LXC 可以为软件提供一个独立的操作系统运行环境。
[root@iZ1608aqb7ntn9Z /]# yum remove docker \ > docker-client \ > docker-client-latest \ > docker-common \ > docker-latest \ > docker-latest-logrotate \ > docker-logrotate \ > docker-engine No match for argument: docker No match for argument: docker-client No match for argument: docker-client-latest No match for argument: docker-common No match for argument: docker-latest No match for argument: docker-latest-logrotate No match for argument: docker-logrotate No match for argument: docker-engine 没有软件包需要移除。 依赖关系解决。 无需任何处理。 完毕!
$ docker run hello-world Unable to find image 'hello-world:latest' locally # 本地没有 latest: Pulling from library/hello-world # pull一个最新版 2db29710123e: Pull complete # pull成功 Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67 Status: Downloaded newer image for hello-world:latest
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/
#可选参数 Search the Docker Hub for images 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) --no-trunc Don\'t truncate output #搜索收藏数大于3000的镜像 $ docker search mysql --filter=STARS=3000 NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 12427 [OK] mariadb MariaDB Server is a high performing open sou… 4787 [OK]
$ docker run c20987f18b13 2022-04-18 07:07:31+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started. 2022-04-18 07:07:31+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2022-04-18 07:07:31+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started. 2022-04-18 07:07:31+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified You need to specify one of the following: - MYSQL_ROOT_PASSWORD - MYSQL_ALLOW_EMPTY_PASSWORD - MYSQL_RANDOM_ROOT_PASSWORD
进入容器
1
[root@iZwz99sm8v95sckz8bd2c4Z ~]# docker run -it [容器ID] /bin/bash
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 703fad61eccb c20987f18b13 "docker-entrypoint.s…" 2 minutes ago Exited (0) 2 minutes ago inspiring_feistel 2e6f020d0299 c20987f18b13 "docker-entrypoint.s…" 3 minutes ago Exited (1) 3 minutes ago angry_stonebraker a4889b27716f hello-world "/hello" 14 minutes ago Exited (0) 14 minutes ago trusting_mcclintock
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f51f3cbb2751 centos "/bin/sh -c 'while t…" 10 seconds ago Up 9 seconds busy_ride
$ docker logs -tf --tail 10 f51f3cbb2751 2022-04-18T07:24:27.364628955Z hi 2022-04-18T07:24:32.365938530Z hi 2022-04-18T07:24:37.367324268Z hi 2022-04-18T07:24:42.368615239Z hi 2022-04-18T07:24:47.369976390Z hi 2022-04-18T07:24:52.371426169Z hi 2022-04-18T07:24:57.372834380Z hi 2022-04-18T07:25:02.374156939Z hi 2022-04-18T07:25:07.375425598Z hi
查看容器中进程信息
1 2 3 4 5
# 命令 docker top 容器id $ docker top f51f3cbb2751 UID PID PPID C STIME TTY TIME CMD root 17874 17853 0 15:24 ? 00:00:00 /bin/sh -c whiletrue;doecho hi;sleep 5;done root 18164 17874 0 15:25 ? 00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 5
$ docker search dockerui NAME DESCRIPTION STARS OFFICIAL AUTOMATED abh1nav/dockerui An updated version of crosbymichael/dockerui… 99 [OK] kevan/dockerui Deprecated: Use uifd/ui-for-docker 15 [OK] ......
$ docker pull abh1nav/dockerui Using default tag: latest latest: Pulling from abh1nav/dockerui Image docker.io/abh1nav/dockerui:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/ a3ed95caeb02: Pull complete 5d3df020ecd3: Pull complete bebf5a3b4dfb: Pull complete e4452c0fe72b: Pull complete 6167d9726b07: Pull complete 53ebae19a314: Pull complete Digest: sha256:a9c6c5393f561a0f42f41cfa80572b666e745d9b419569c42bac1e5cf9ceda32 Status: Downloaded newer image for abh1nav/dockerui:latest docker.io/abh1nav/dockerui:latest
$ docker search portainer NAME DESCRIPTION STARS OFFICIAL AUTOMATED portainer/portainer This Repo is now deprecated, use portainer/p… 2201 portainer/portainer-ce Portainer CE - a lightweight service deliver… 1100 ......
$ docker pull portainer/portainer Using default tag: latest latest: Pulling from portainer/portainer 94cfa856b2b1: Pull complete 49d59ee0881a: Pull complete a2300fd28637: Pull complete Digest: sha256:fb45b43738646048a0a0cc74fcee2865b69efde857e710126084ee5de9be0f3f Status: Downloaded newer image for portainer/portainer:latest docker.io/portainer/portainer:latest
# 关闭容器 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c70636684cd8 nginx "/docker-entrypoint.…" 11 minutes ago Up 11 minutes 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx 959047ff6deb abh1nav/dockerui "./dockerui" About an hour ago Up About an hour 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp dockerui f51f3cbb2751 centos "/bin/sh -c 'while t…" About an hour ago Up About an hour busy_ride