Docker container learning (1)

table of Contents

、 、 Hello world

docker command

docker run hello-world

docker images

docker ps -a

ps afx | grep docker -A 1

tips: Automatic completion tool



、 、 Hello world

docker command

[root@yangrenhao ~]# docker //View the docker command help

Usage: docker [OPTIONS] COMMAND



A self-sufficient runtime for containers



Options:

--config string Location of client config files (default "/root/.docker")

-D, --debug Enable debug mode

-H, --host list Daemon socket(s) to connect to

-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")

(default "info")

--tls Use TLS; implied by --tlsverify

--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")

--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")

--tlskey string Path to TLS key file (default "/root/.docker/key.pem")

--tlsverify Use TLS and verify the remote

-v, --version Print version information and quit



Management Commands:

config Manage Docker configs

container Manage containers

image Manage images

network Manage networks

node Manage Swarm nodes

plugin Manage plugins

secret Manage Docker secrets

service Manage services

stack Manage Docker stacks

swarm Manage Swarm

system Manage Docker

trust Manage trust on Docker images

volume Manage volumes



Commands:

attach Attach local standard input, output, and error streams to a running container

build Build an image from a Dockerfile

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

events Get real time events from the server

exec Run a command in a running container

export Export a container's filesystem as a tar archive

history Show the history of an image

images List images

import Import the contents from a tarball to create a filesystem image

info Display system-wide information

inspect Return low-level information on Docker objects

kill Kill one or more running containers

load Load an image from a tar archive or STDIN

login Log in to a Docker registry

logout Log out from a Docker registry

logs Fetch the logs of a container

pause Pause all processes within one or more containers

port List port mappings or a specific mapping for the container

ps List containers

pull Pull an image or a repository from a registry

push Push an image or a repository to a registry

rename Rename a container

restart Restart one or more containers

rm Remove one or more containers

rmi Remove one or more images

run Run a command in a new container

save Save one or more images to a tar archive (streamed to STDOUT by default)

search Search the Docker Hub for images

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

tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

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

version Show the Docker version information

wait Block until one or more containers stop, then print their exit codes



Run 'docker COMMAND --help' for more information on a command.

docker run hello-world

[root@yangrenhao ~]# docker run hello-world    

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:fc6a51919cfeb2e6763f62b6d9e8815acbf7cd2e476ea353743570610737b752
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/

docker images

[root@yangrenhao ~]# docker images //View installed docker images

REPOSITORY                                                        TAG                 IMAGE ID            CREATED             SIZE
tomcat                                                            latest              6fa48e047721        2 months ago        507MB
registry.aliyuncs.com/google_containers/kube-proxy                v1.17.0             7d54289267dc        2 months ago        116MB
registry.aliyuncs.com/google_containers/kube-apiserver            v1.17.0             0cae8d5cc64c        2 months ago        171MB
registry.aliyuncs.com/google_containers/kube-scheduler            v1.17.0             78c190f736b1        2 months ago        94.4MB
registry.aliyuncs.com/google_containers/kube-controller-manager   v1.17.0             5eb3b7486872        2 months ago        161MB
registry.aliyuncs.com/google_containers/coredns                   1.6.5               70f311871ae1        3 months ago        41.6MB
registry.aliyuncs.com/google_containers/etcd                      3.4.3-0             303ce5db0e90        4 months ago        288MB
quay.io/coreos/flannel                                            v0.11.0-amd64       ff281650a721        13 months ago       52.6MB
quay-mirror.qiniu.com/coreos/flannel                              v0.11.0-amd64       ff281650a721        13 months ago       52.6MB
hello-world                                                       latest              fce289e99eb9        14 months ago       1.84kB
registry.aliyuncs.com/google_containers/pause                     3.1                 da86e6ba6ca1        2 years ago         742kB

 

docker ps -a

[root@yangrenhao ~]# docker ps

Show only running

[root@yangrenhao ~]# docker ps -a

Show all running, including abnormal exit

 

[root@yangrenhao ~]# docker ps -a
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS                     PORTS                    NAMES
93331fbd75ed        hello-world                                         "/hello"                 24 hours ago        Exited (0) 24 hours ago                             amazing_liskov

ps afx | grep docker -A 1

View the detailed parent-child relationship of the docker process

[root@yangrenhao ~]# ps afx |grep docker -A 1
 9264 pts/1    Sl+    0:01  |       \_ docker run -d -p 80:80 httpd
 6578 ?        Ss     0:00  \_ sshd: root@pts/2
--
13746 pts/2    S+     0:00          \_ grep --color=auto docker -A 1
 1074 ?        Ss     0:43 /usr/sbin/crond -n
--
11486 ?        Ssl  1617:07 /usr/bin/dockerd
11493 ?        Ssl  169:26  \_ docker-containerd --config /var/run/docker/containerd/containerd.toml
12513 ?        Sl     5:14  |   \_ docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/cefe736981aacb01e7424b524ed5a215b5cde820d30438661f48cf60de8023e7 -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
12572 ?        Ss     0:00  |   |   \_ /pause
12523 ?        Sl     4:48  |   \_ docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/7cd116581c77968660c58c9535d63db7b4404b4897e468e0f7fb33f9ba33ed2f -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
12591 ?        Ss     0:00  |   |   \_ /pause
12547 ?        Sl     4:57  |   \_ docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/f9aecdc5c372ccde3ae4f2757b4c514586ce8279fd747874a45633f9a7c21be0 -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
12603 ?        Ss     0:00  |   |   \_ /pause
12578 ?        Sl     4:43  |   \_ docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/2d4b9788888e17ff47f1a78327a3b7278202851bf3e10783989b215e88ac4cae -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
12614 ?        Ss     0:00  |   |   \_ /pause
12695 ?        Sl     5:22  |   \_ docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/f0bef593547ba62223d9f1de6fc0a30da10a186523a889625ffcc6b29ef10b07 -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
23571 ?        Sl     0:44  |   \_ docker-containerd-shim -namespace moby -workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/b80c51d7d4d0d1f2b75297059224c9ddb86f4724d0d51058294215d7e1d41b0b -address /var/run/docker/containerd/docker-containerd.sock -containerd-binary /usr/bin/docker-containerd -runtime-root /var/run/docker/runtime-runc
23630 ?        Ssl   81:58  |       \_ kube-scheduler --authentication-kubeconfig=/etc/kubernetes/scheduler.conf --authorization-kubeconfig=/etc/kubernetes/scheduler.conf --bind-address=127.0.0.1 --kubeconfig=/etc/kubernetes/scheduler.conf --leader-elect=true
19930 ?        Sl     0:17  \_ /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.17.0.2 -container-port 8080
12894 ?        Ssl  3333:32 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --cgroup-driver=cgroupfs --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.1

 

 

tips: Automatic completion tool

[root@yangrenhao ~]# yum install bash-completion
已加载插件:fastestmirror
Determining fastest mirrors
base                                                                     | 3.6 kB  00:00:00
docker-ce-stable                                                         | 3.5 kB  00:00:00
epel                                                                     | 5.4 kB  00:00:00
extras                                                                   | 2.9 kB  00:00:00
kubernetes/signature                                                     |  454 B  00:00:00
kubernetes/signature                                                     | 1.4 kB  00:00:03 !!!
updates                                                                  | 2.9 kB  00:00:00
(1/6): epel/x86_64/updateinfo                                            | 1.0 MB  00:00:08
(2/6): kubernetes/primary                                                |  64 kB  00:00:06
(3/6): extras/7/x86_64/primary_db                                        | 159 kB  00:00:07
(4/6): docker-ce-stable/x86_64/primary_db                                |  38 kB  00:00:09
(5/6): epel/x86_64/primary_db                                            | 6.7 MB  00:00:09
(6/6): updates/7/x86_64/primary_db                                       | 6.7 MB  00:00:01
kubernetes                                                                              469/469
正在解决依赖关系
--> 正在检查事务
---> 软件包 bash-completion.noarch.1.2.1-6.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================================
 Package                     架构               版本                     源                大小
================================================================================================
正在安装:
 bash-completion             noarch             1:2.1-6.el7              base              85 k

事务概要
================================================================================================
安装  1 软件包

总下载量:85 k
安装大小:259 k
Is this ok [y/d/N]: y
Downloading packages:
bash-completion-2.1-6.el7.noarch.rpm                                     |  85 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : 1:bash-completion-2.1-6.el7.noarch                                          1/1
  验证中      : 1:bash-completion-2.1-6.el7.noarch                                          1/1

已安装:
  bash-completion.noarch 1:2.1-6.el7

完毕!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/xlyrh/article/details/104526420