Docker基础用法篇
Docker基础用法篇
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.安装docker
1>.依赖的基础环境
64 bits CPU
Linux Kerner 3.10+(虽说Redhat 2.6.x内核也可以运行Docker,这是由于红帽为其打了很多补丁,但运行的稳定性极差,因此不推荐在生产环境中使用CentOS 6.x版本)
Linux Kernel cgroups and namespaces
2>.CentOS 7
“extras” repository仓库中存在docker的安装包,但是版本较低,因此我们不推荐使用CentOS自带的仓库软件包。
3>.下载docker-ce的仓库
[root@node101.yinzhengjie.org.cn ~]# cd /etc/yum.repos.d/
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]#
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]# wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
---- ::-- https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, :f000:::::
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:... connected.
HTTP request sent, awaiting response... OK
Length: (.4K) [application/octet-stream]
Saving to: ‘docker-ce.repo’ %[=============================================================================================>] , --.-K/s in 0s -- :: ( MB/s) - ‘docker-ce.repo’ saved [/] [root@node101.yinzhengjie.org.cn /etc/yum.repos.d]#
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]# cat docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/stable #不难发现这个地址依旧时Docker官网的地址,下载镜像速度可能还是很慢,我们需要手动修改。
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://download.docker.com/linux/centos/7/source/stable
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/edge
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/edge
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://download.docker.com/linux/centos/7/source/edge
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/test
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://download.docker.com/linux/centos/7/source/test
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://download.docker.com/linux/centos/7/$basearch/nightly
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/nightly
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://download.docker.com/linux/centos/7/source/nightly
enabled=
gpgcheck=
gpgkey=https://download.docker.com/linux/centos/gpg
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]#
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]#
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]# wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo --2019-10-16 21:32:50-- https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]# cat docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/$basearch/stable
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-$basearch/stable
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/stable
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/$basearch/edge
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-$basearch/edge
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/edge
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/$basearch/test
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-$basearch/test
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/test
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/$basearch/nightly
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-$basearch/nightly
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg [docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/nightly
enabled=
gpgcheck=
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]#
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]# cat docker-ce.repo
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
base | 3.6 kB ::
docker-ce-stable | 3.5 kB ::
Not using downloaded docker-ce-stable/repomd.xml because it is older than what we have:
Current : Sat Oct ::
Downloaded: Thu Sep ::
extras | 2.9 kB ::
updates | 2.9 kB ::
repo id repo name status
base//x86_64 CentOS- - Base ,
docker-ce-stable/x86_64 Docker CE Stable - x86_64 #我们发现是有docker安装包的
extras//x86_64 CentOS- - Extras
updates//x86_64 CentOS- - Updates
repolist: ,
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]#
[root@node101.yinzhengjie.org.cn /etc/yum.repos.d]# yum repolist #验证是否docker-ce的包
[root@node101.yinzhengjie.org.cn ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo #除了使用上面的清华源,咱们还可以使用阿里源,一步到位,无需修改。
---- ::-- https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 1.180.31.241, 124.116.187.114, 36.99.142.195, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|1.180.31.241|:... connected.
HTTP request sent, awaiting response... OK
Length: (.6K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/docker-ce.repo’ %[=============================================================================================>] , --.-K/s in 0s -- :: (29.0 MB/s) - ‘/etc/yum.repos.d/docker-ce.repo’ saved [/] [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/stable
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/stable
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-edge]
name=Docker CE Edge - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/edge
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-edge-debuginfo]
name=Docker CE Edge - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/edge
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-edge-source]
name=Docker CE Edge - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/edge
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/test
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/test
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/test
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/nightly
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/nightly
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg [docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/nightly
enabled=
gpgcheck=
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo #除了使用上面的清华源,咱们还可以使用阿里源,一步到位,无需修改。
4>.安装Docker-ce
[root@node101.yinzhengjie.org.cn ~]# yum -y install docker-ce #安装Docker免费版本
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 :19.03.-.el7 will be installed
--> Processing Dependency: container-selinux >= :2.74 for package: :docker-ce-19.03.-.el7.x86_64
--> Processing Dependency: containerd.io >= 1.2.- for package: :docker-ce-19.03.-.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: :docker-ce-19.03.-.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch :2.107-.el7 will be installed
---> Package containerd.io.x86_64 :1.2.-3.2.el7 will be installed
---> Package docker-ce-cli.x86_64 :19.03.-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved =======================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================
Installing:
docker-ce x86_64 :19.03.-.el7 docker-ce-stable M
Installing for dependencies:
container-selinux noarch :2.107-.el7 extras k
containerd.io x86_64 1.2.-3.2.el7 docker-ce-stable M
docker-ce-cli x86_64 :19.03.-.el7 docker-ce-stable M Transaction Summary
=======================================================================================================================================
Install Package (+ Dependent packages) Total size: M
Total download size: M
Installed size: M
Downloading packages:
No Presto metadata available for docker-ce-stable
warning: /var/cache/yum/x86_64//docker-ce-stable/packages/containerd.io-1.2.-3.2.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key
ID 621e9f35: NOKEYPublic key for containerd.io-1.2.-3.2.el7.x86_64.rpm is not installed
containerd.io-1.2.-3.2.el7.x86_64.rpm | MB ::
Retrieving key from https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <docker@docker.com>"
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : :container-selinux-2.107-.el7.noarch /
Installing : containerd.io-1.2.-3.2.el7.x86_64 /
Installing : :docker-ce-cli-19.03.-.el7.x86_64 /
Installing : :docker-ce-19.03.-.el7.x86_64 /
Verifying : :docker-ce-19.03.-.el7.x86_64 /
Verifying : :docker-ce-cli-19.03.-.el7.x86_64 /
Verifying : containerd.io-1.2.-3.2.el7.x86_64 /
Verifying : :container-selinux-2.107-.el7.noarch / Installed:
docker-ce.x86_64 :19.03.-.el7 Dependency Installed:
container-selinux.noarch :2.107-.el7 containerd.io.x86_64 :1.2.-3.2.el7 docker-ce-cli.x86_64 :19.03.-.el7 Complete!
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# yum -y install docker-ce #安装Docker免费版本
[root@node101.yinzhengjie.org.cn ~]# docker version
Client: Docker Engine - Community #客户端版本信息
Version: 19.03.
API version: 1.40
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct ::
OS/Arch: linux/amd64
Experimental: false Server: Docker Engine - Community #服务端版本信息
Engine:
Version: 19.03.
API version: 1.40 (minimum version 1.12)
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct ::
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.
GitCommit: fec3683
[root@node101.yinzhengjie.org.cn ~]#
5>.使用阿里docker镜像加速器(需要登录阿里云账号,每个人都有自己的加速器)
[root@node101.yinzhengjie.org.cn ~]# mkdir /etc/docker
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# vi /etc/docker/daemon.json
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /etc/docker/daemon.json #将阿里云的加速地址写入该配置文件中。
{
"registry-mirrors": ["https://tuv7rqqq.mirror.aliyuncs.com"]
}
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# systemctl daemon-reload
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# systemctl start docker
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker info #查看docker更详细的信息,可以在"Registry Mirrors"看到加速URL是否配置正确。
Client:
Debug Mode: false Server:
Containers: #当前容器个数
Running: #当前处于运行状态的容器
Paused: #暂停状态的容器
Stopped: #停止状态的容器
Images: #镜像版本
Server Version: 19.03. #服务器版本
Storage Driver: overlay2 #存储去打动后端,docker镜像是封层构建联合挂载的,他们要求必须使用特殊的文件系统,我们使用的xfs和ext是不支持的!目前支持aufs和overlay2文件系统,默认使用的就是overlay2文件系统。
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.-.el7.x86_64
Operating System: CentOS Linux (Core)
OSType: linux
Architecture: x86_64
CPUs:
Total Memory: .683GiB
Name: node101.yinzhengjie.org.cn
ID: S6JF:PNVN:QCOA:5YM4:URXE:RK5C:S6F6:H3TD:BBMW:BVLK:ZGIN:2KTW
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/
Registry Mirrors: #加速镜像信息,这是我使用的阿里镜像加速,如果你也有这个信息说明你配置是成功的
https://tuv7rqqq.mirror.aliyuncs.com/
Live Restore Enabled: false [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker info #查看docker更详细的信息,可以在"Registry Mirrors"看到加速URL是否配置正确。
二.docker常用操作案例
1>.docker search(可以根据关键词搜索镜像文件的命令)
[root@node101.yinzhengjie.org.cn ~]# docker search --help #查看该命令的帮助信息 Usage: docker search [OPTIONS] TERM 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 )
--no-trunc Don't truncate output
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker search --help #查看该命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS…
bitnami/nginx Bitnami nginx Docker Image [OK]
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho…
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… [OK]
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… [OK]
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. [OK]
centos/nginx--centos7 Platform for running nginx 1.8 or building n…
centos/nginx--centos7 Platform for running nginx 1.12 or building …
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… [OK]
1science/nginx Nginx Docker images that include Consul Temp… [OK]
mailu/nginx Mailu nginx frontend [OK]
pebbletech/nginx-proxy nginx-proxy sets up a container running ngin… [OK]
travix/nginx NGinx reverse proxy [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX [OK]
centos/nginx--centos7 Platform for running nginx 1.10 or building …
wodby/nginx Generic nginx [OK]
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker search nginx #查看包含"nginx"字样的镜像名称
2>.docker pull(下载docker镜像到本地,该命令等效于"docker image pull")
[root@node101.yinzhengjie.org.cn ~]# docker image push --help #查看该命令的帮助信息 Usage: docker image push [OPTIONS] NAME[:TAG] Push an image or a repository to a registry Options:
--disable-content-trust Skip image signing (default true)
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image push --help #查看该命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker image pull nginx:1.14-alpine #注意:alpine版本表示专门用于构建容器小镜象的发行版,生产环境不推荐使用,学习阶段为了节省带宽可以这样玩。
1.14-alpine: Pulling from library/nginx
bdf0201b3a05: Pull complete
3d0a573c81ed: Pull complete
8129faeb2eb6: Pull complete
3dc99f571daf: Pull complete
Digest: sha256:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7
Status: Downloaded newer image for nginx:1.14-alpine
docker.io/library/nginx:1.14-alpine
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image pull nginx:1.14-alpine #注意:alpine版本表示专门用于构建容器小镜象的发行版,生产环境不推荐使用,学习阶段为了节省带宽可以这样玩。另外:nginx发行版本编号偶数为稳定版本。
[root@node101.yinzhengjie.org.cn ~]# docker pull busybox #注意:busybox镜像可以理解为微小型的Linux虚拟机,据说安卓系统就用到了它。另外:如果我们只是指定仓库名称busybox,它默认回去下载busybox:latest这个tag版本。
Using default tag: latest
latest: Pulling from library/busybox
7c9d20b9b6cd: Pull complete
Digest: sha256:fe301db49df08c384001ed752dff6d52b4305a73a7f608f21528048e8a08b51e
Status: Downloaded newer image for busybox:latest
docker.io/library/busybox:latest
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker pull busybox #注意:busybox镜像可以理解为微小型的Linux虚拟机,据说安卓系统就用到了它。另外:如果我们只是指定仓库名称busybox,它默认回去下载busybox:latest这个tag版本。
3>.docker images(列出本地所有可用镜像。该命令等效于"docker image ls")
[root@node101.yinzhengjie.org.cn ~]# docker image ls --help #查看该命令的帮助信息 Usage: docker image ls [OPTIONS] [REPOSITORY[:TAG]] List images Aliases:
ls, images, list Options:
-a, --all Show all images (default hides intermediate images)
--digests Show digests
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print images using a Go template
--no-trunc Don't truncate output
-q, --quiet Only show numeric IDs
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image ls --help #查看该命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker images #列出已经下载的镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 19485c79a9bb weeks ago .22MB
nginx 1.14-alpine 8a2fb25a19f5 months ago 16MB
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker images #列出已经下载的镜像
[root@node101.yinzhengjie.org.cn ~]# docker image ls #列出已经下载的镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 19485c79a9bb weeks ago .22MB
nginx 1.14-alpine 8a2fb25a19f5 months ago 16MB
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image ls #列出已经下载的镜像
[root@node101.yinzhengjie.org.cn ~]# docker image ls --no-trunc #显示完整的IMAGE ID信息
REPOSITORY TAG IMAGE ID CREATED
SIZEbusybox latest sha256:19485c79a9bbdca205fce4f791efeaa2a103e23431434696cc54fdd939e9198d weeks ago
.22MBnginx 1.14-alpine sha256:8a2fb25a19f5dc1528b7a3fabe8b3145ff57fe10e4f1edac6c718a3cf4aa4b73 months ago
16MB[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image ls --no-trunc #显示完整的IMAGE ID信息
4>.docker rmi(删除指定镜像,该命令等效于"docker image rm")
[root@node101.yinzhengjie.org.cn ~]# docker image rm --help #查看该命令帮助信息 Usage: docker image rm [OPTIONS] IMAGE [IMAGE...] Remove one or more images Aliases:
rm, rmi, remove Options:
-f, --force Force removal of the image
--no-prune Do not delete untagged parents
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image rm --help #查看该命令帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.14-alpine 8a2fb25a19f5 months ago 16MB
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image rm nginx:1.14-alpine #删除已经下载的镜像,需要指定版本号,若不指定默认会删除nginx:latest镜像哟
Untagged: nginx:1.14-alpine
Untagged: nginx@sha256:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7
Deleted: sha256:8a2fb25a19f5dc1528b7a3fabe8b3145ff57fe10e4f1edac6c718a3cf4aa4b73
Deleted: sha256:f68a8bcb9dbd06e0d2750eabf63c45f51734a72831ed650d2349775865d5fc20
Deleted: sha256:cbf2c7789332fe231e8defa490527a7b2c3ae8589997ceee00895f3263f0a8cf
Deleted: sha256:894f3fad7e6ecd7f24e88340a44b7b73663a85c0eb7740e7ade169e9d8491a4c
Deleted: sha256:a464c54f93a9e88fc1d33df1e0e39cca427d60145a360962e8f19a1dbf900da9
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image rm nginx:1.14-alpine #删除已经下载的镜像,需要指定版本号,若不指定默认会删除nginx:latest镜像哟
[root@node101.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 19485c79a9bb weeks ago .22MB
nginx 1.14-alpine 8a2fb25a19f5 months ago 16MB
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker rmi busybox #删除busybox镜像
Untagged: busybox:latest
Untagged: busybox@sha256:fe301db49df08c384001ed752dff6d52b4305a73a7f608f21528048e8a08b51e
Deleted: sha256:19485c79a9bbdca205fce4f791efeaa2a103e23431434696cc54fdd939e9198d
Deleted: sha256:6c0ea40aef9d2795f922f4e8642f0cd9ffb9404e6f3214693a1fd45489f38b44
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.14-alpine 8a2fb25a19f5 months ago 16MB
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker rmi busybox #删除busybox镜像
5>.docker create(创建容器,该命令等效于"docker container create")
[root@node101.yinzhengjie.org.cn ~]# docker container create --help #查看该命令的帮助信息 Usage: docker container create [OPTIONS] IMAGE [COMMAND] [ARG...] Create a new container Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
-a, --attach list Attach to STDIN, STDOUT or STDERR
--blkio-weight uint16 Block IO (relative weight), between and , or to disable (default )
--blkio-weight-device list Block IO weight (relative device weight) (default [])
--cap-add list Add Linux capabilities
--cap-drop list Drop Linux capabilities
--cgroup-parent string Optional parent cgroup for the container
--cidfile string Write the container ID to the file
--cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-period int Limit CPU real-time period in microseconds
--cpu-rt-runtime int Limit CPU real-time runtime in microseconds
-c, --cpu-shares int CPU shares (relative weight)
--cpus decimal Number of CPUs
--cpuset-cpus string CPUs in which to allow execution (-, ,)
--cpuset-mems string MEMs in which to allow execution (-, ,)
--device list Add a host device to the container
--device-cgroup-rule list Add a rule to the cgroup allowed devices list
--device-read-bps list Limit read rate (bytes per second) from a device (default [])
--device-read-iops list Limit read rate (IO per second) from a device (default [])
--device-write-bps list Limit write rate (bytes per second) to a device (default [])
--device-write-iops list Limit write rate (IO per second) to a device (default [])
--disable-content-trust Skip image verification (default true)
--dns list Set custom DNS servers
--dns-option list Set DNS options
--dns-search list Set custom DNS search domains
--domainname string Container NIS domain name
--entrypoint string Overwrite the default ENTRYPOINT of the image
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
--expose list Expose a port or a range of ports
--gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs)
--group-add list Add additional groups to join
--health-cmd string Command to run to check health
--health-interval duration Time between running the check (ms|s|m|h) (default 0s)
--health-retries int Consecutive failures needed to report unhealthy
--health-start-period duration Start period for the container to initialize before starting health-retries countdown
(ms|s|m|h) (default 0s)
--health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s)
--help Print usage
-h, --hostname string Container host name
--init Run an init inside the container that forwards signals and reaps processes
-i, --interactive Keep STDIN open even if not attached
--ip string IPv4 address (e.g., 172.30.100.104)
--ip6 string IPv6 address (e.g., :db8::)
--ipc string IPC mode to use
--isolation string Container isolation technology
--kernel-memory bytes Kernel memory limit
-l, --label list Set meta data on a container
--label-file list Read in a line delimited file of labels
--link list Add link to another container
--link-local-ip list Container IPv4/IPv6 link-local addresses
--log-driver string Logging driver for the container
--log-opt list Log driver options
--mac-address string Container MAC address (e.g., :d0:c6:0a::)
-m, --memory bytes Memory limit
--memory-reservation bytes Memory soft limit
--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--memory-swappiness int Tune container memory swappiness ( to ) (default -)
--mount mount Attach a filesystem mount to the container
--name string Assign a name to the container
--network network Connect a container to a network
--network-alias list Add network-scoped alias for the container
--no-healthcheck Disable any container-specified HEALTHCHECK
--oom-kill-disable Disable OOM Killer
--oom-score-adj int Tune host's OOM preferences (-1000 to 1000)
--pid string PID namespace to use
--pids-limit int Tune container pids limit (set - for unlimited)
--privileged Give extended privileges to this container
-p, --publish list Publish a container's port(s) to the host
-P, --publish-all Publish all exposed ports to random ports
--read-only Mount the container's root filesystem as read only
--restart string Restart policy to apply when a container exits (default "no")
--rm Automatically remove the container when it exits
--runtime string Runtime to use for this container
--security-opt list Security Options
--shm-size bytes Size of /dev/shm
--stop-signal string Signal to stop a container (default "SIGTERM")
--stop-timeout int Timeout (in seconds) to stop a container
--storage-opt list Storage driver options for the container
--sysctl map Sysctl options (default map[])
--tmpfs list Mount a tmpfs directory
-t, --tty Allocate a pseudo-TTY
--ulimit ulimit Ulimit options (default [])
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
--userns string User namespace to use
--uts string UTS namespace to use
-v, --volume list Bind mount a volume
--volume-driver string Optional volume driver for the container
--volumes-from list Mount volumes from the specified container(s)
-w, --workdir string Working directory inside the container
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container create --help #查看该命令的帮助信息
6>.docker start(启动一个或多个容器,该命令等效于"docker container start")
[root@node101.yinzhengjie.org.cn ~]# docker start --help #查看该名命令的帮助信息 Usage: docker start [OPTIONS] CONTAINER [CONTAINER...] Start one or more stopped containers Options:
-a, --attach Attach STDOUT/STDERR and forward signals
--detach-keys string Override the key sequence for detaching a container
-i, --interactive Attach container's STDIN
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker start --help #查看该名命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb5fb9d1adc7 busybox:latest "sh" minutes ago Exited () minutes ago b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container start -i -a b1 #启动一个已经退出的容器
/ #
/ #
/ # ps
PID USER TIME COMMAND
root : sh
root : ps
/ #
[root@node101.yinzhengjie.org.cn ~]# docker container start -i -a b1 #启动一个已经退出的容器
[root@node101.yinzhengjie.org.cn ~]# docker container ps #容器启动成功后,可用看到正在运行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb5fb9d1adc7 busybox:latest "sh" minutes ago Up minutes b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb5fb9d1adc7 busybox:latest "sh" minutes ago Up minutes b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container ps #容器启动成功后,可用看到正在运行的容器
7>.docker stop(停止一个或多个运行中的容器,该命令等效于"docker container stop")
8>.docker kill(强行停止一个或多个运行中的容器,该命令等效于"docker container kill")
[root@node101.yinzhengjie.org.cn ~]# docker kill --help #查看该命令的帮助信息 Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...] Kill one or more running containers Options:
-s, --signal string Signal to send to the container (default "KILL")
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker kill --help #查看该命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb5fb9d1adc7 busybox:latest "sh" minutes ago Up minutes b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker kill b1 #强行停止b1容器的运行
b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker kill b1 #强行停止b1容器的运行
9>.docker run(运行一个新的容器并启动该容器,该命令等效于"docker container run")
[root@node101.yinzhengjie.org.cn ~]# docker run --help #查看该命令的帮助信息 Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run a command in a new container Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
-a, --attach list Attach to STDIN, STDOUT or STDERR
--blkio-weight uint16 Block IO (relative weight), between and , or to disable (default )
--blkio-weight-device list Block IO weight (relative device weight) (default [])
--cap-add list Add Linux capabilities
--cap-drop list Drop Linux capabilities
--cgroup-parent string Optional parent cgroup for the container
--cidfile string Write the container ID to the file
--cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-period int Limit CPU real-time period in microseconds
--cpu-rt-runtime int Limit CPU real-time runtime in microseconds
-c, --cpu-shares int CPU shares (relative weight)
--cpus decimal Number of CPUs
--cpuset-cpus string CPUs in which to allow execution (-, ,)
--cpuset-mems string MEMs in which to allow execution (-, ,)
-d, --detach Run container in background and print container ID
--detach-keys string Override the key sequence for detaching a container
--device list Add a host device to the container
--device-cgroup-rule list Add a rule to the cgroup allowed devices list
--device-read-bps list Limit read rate (bytes per second) from a device (default [])
--device-read-iops list Limit read rate (IO per second) from a device (default [])
--device-write-bps list Limit write rate (bytes per second) to a device (default [])
--device-write-iops list Limit write rate (IO per second) to a device (default [])
--disable-content-trust Skip image verification (default true)
--dns list Set custom DNS servers
--dns-option list Set DNS options
--dns-search list Set custom DNS search domains
--domainname string Container NIS domain name
--entrypoint string Overwrite the default ENTRYPOINT of the image
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
--expose list Expose a port or a range of ports
--gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs)
--group-add list Add additional groups to join
--health-cmd string Command to run to check health
--health-interval duration Time between running the check (ms|s|m|h) (default 0s)
--health-retries int Consecutive failures needed to report unhealthy
--health-start-period duration Start period for the container to initialize before starting health-retries countdown
(ms|s|m|h) (default 0s)
--health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s)
--help Print usage
-h, --hostname string Container host name
--init Run an init inside the container that forwards signals and reaps processes
-i, --interactive Keep STDIN open even if not attached
--ip string IPv4 address (e.g., 172.30.100.104)
--ip6 string IPv6 address (e.g., :db8::)
--ipc string IPC mode to use
--isolation string Container isolation technology
--kernel-memory bytes Kernel memory limit
-l, --label list Set meta data on a container
--label-file list Read in a line delimited file of labels
--link list Add link to another container
--link-local-ip list Container IPv4/IPv6 link-local addresses
--log-driver string Logging driver for the container
--log-opt list Log driver options
--mac-address string Container MAC address (e.g., :d0:c6:0a::)
-m, --memory bytes Memory limit
--memory-reservation bytes Memory soft limit
--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--memory-swappiness int Tune container memory swappiness ( to ) (default -)
--mount mount Attach a filesystem mount to the container
--name string Assign a name to the container
--network network Connect a container to a network
--network-alias list Add network-scoped alias for the container
--no-healthcheck Disable any container-specified HEALTHCHECK
--oom-kill-disable Disable OOM Killer
--oom-score-adj int Tune host's OOM preferences (-1000 to 1000)
--pid string PID namespace to use
--pids-limit int Tune container pids limit (set - for unlimited)
--privileged Give extended privileges to this container
-p, --publish list Publish a container's port(s) to the host
-P, --publish-all Publish all exposed ports to random ports
--read-only Mount the container's root filesystem as read only
--restart string Restart policy to apply when a container exits (default "no")
--rm Automatically remove the container when it exits
--runtime string Runtime to use for this container
--security-opt list Security Options
--shm-size bytes Size of /dev/shm
--sig-proxy Proxy received signals to the process (default true)
--stop-signal string Signal to stop a container (default "SIGTERM")
--stop-timeout int Timeout (in seconds) to stop a container
--storage-opt list Storage driver options for the container
--sysctl map Sysctl options (default map[])
--tmpfs list Mount a tmpfs directory
-t, --tty Allocate a pseudo-TTY
--ulimit ulimit Ulimit options (default [])
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
--userns string User namespace to use
--uts string UTS namespace to use
-v, --volume list Bind mount a volume
--volume-driver string Optional volume driver for the container
--volumes-from list Mount volumes from the specified container(s)
-w, --workdir string Working directory inside the container
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker run --help #查看该命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker run --name b1 -it busybox:latest #注意,"--name"表示给该容器起一个名称,"-i"选项表示交互式,"-t"表示启动一个终端,启动时指定的Image为"busybox:latest"
/ #
/ # ps
PID USER TIME COMMAND
root : sh
root : ps
/ #
/ # ls /bin/ | wc -l / #
/ # httpd -h
httpd: option requires an argument -- h
BusyBox v1.31.0 (-- :: UTC) multi-call binary. Usage: httpd [-ifv[v]] [-c CONFFILE] [-p [IP:]PORT] [-u USER[:GRP]] [-r REALM] [-h HOME]
or httpd -d/-e/-m STRING Listen for incoming HTTP requests -i Inetd mode
-f Don't daemonize
-v[v] Verbose
-p [IP:]PORT Bind to IP:PORT (default *:)
-u USER[:GRP] Set uid/gid after binding to port
-r REALM Authentication Realm for Basic Authentication
-h HOME Home directory (default .)
-c FILE Configuration file (default {/etc,HOME}/httpd.conf)
-m STRING MD5 crypt STRING
-e STRING HTML encode STRING
-d STRING URL decode STRING
/ #
/ # / # mkdir /data/html -pv
created directory: '/data/'
created directory: '/data/html'
/ #
/ # vi /data/html/index.html
/ #
/ # cat /data/html/index.html
Busybox httpd server.
yinzhengjie dao ci yi you !
/ #
/ # httpd -f -h /data/html/ #此时我们就启动了一个httpd服务,我们可用通过客户端去访问
[root@node101.yinzhengjie.org.cn ~]# docker run --name b1 -it busybox:latest #注意,"--name"表示给该容器起一个名称,"-i"选项表示交互式,"-t"表示启动一个终端,启动时指定的Image为"busybox:latest",在busybox中启动一个httpd服务
[root@node101.yinzhengjie.org.cn ~]# docker container inspect b1 | grep "IPAddress" #查看b1容器的IP地址,用于访问b1容器内的httpd服务。
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# curl 172.17.0.2 #访问b1容器的httpd服务
Busybox httpd server.
yinzhengjie dao ci yi you !
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container inspect b1 | grep "IPAddress" #查看b1容器的IP地址,用于访问b1容器内的httpd服务。
/ #
/ # httpd -f -h /data/html/ #使用"ctrl + c"终止容器中的进程
^C
/ #
/ # exit #退出b1容器
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker ps #发现没有正在运行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker ps -a #不难发现,容器依旧还在只不过状态为Exited啦。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb5fb9d1adc7 busybox:latest "sh" minutes ago Exited () seconds ago b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
/ # httpd -f -h /data/html/ #使用"ctrl + c"终止容器中的进程
[root@node101.yinzhengjie.org.cn ~]# docker run --name web01 -d nginx:1.14-alpine #启动一个nginx容器之后我们可用访问它
ce713ceaa586a9790b7d11602666826a05e64551bef184cb504dbfcaf5f5ac9a
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ce713ceaa586 nginx:1.14-alpine "nginx -g 'daemon of…" seconds ago Up seconds /tcp web01
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker inspect web01 | grep "IPAddress"
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# curl 172.17.0.2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker run --name web01 -d nginx:1.14-alpine #启动一个nginx容器之后我们可用访问它
[root@node101.yinzhengjie.org.cn ~]# docker run --name redis01 -d redis:-alpine #启动一个redis容器,注意:如果镜像不存在他会自动去官网下载对应的镜像哟~
Unable to find image 'redis:4-alpine' locally
-alpine: Pulling from library/redis
9d48c3bd43c5: Pull complete
6bcae78f4e99: Pull complete
8cb2d2938e96: Pull complete
b8ca2dc963b3: Pull complete
6d2f7873656f: Pull complete
ad232b4fa0bb: Pull complete
Digest: sha256:e59e6cab7ada6fa8cfeb9ad4c5b82bf7947bf3620cafc17e19fdbff01b239981
Status: Downloaded newer image for redis:-alpine
b16c5b671f318bd1d258512df1aa67ff93f2175f3c79067aa59e59128bcfae4c
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b16c5b671f31 redis:-alpine "docker-entrypoint.s…" seconds ago Up seconds /tcp redis01
ce713ceaa586 nginx:1.14-alpine "nginx -g 'daemon of…" minutes ago Up minutes /tcp web01
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container exec -it redis01 /bin/sh
/data #
/data # ps
PID USER TIME COMMAND
redis : redis-server
root : /bin/sh
root : ps
/data #
/data #
/data # netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0.0.0.0: 0.0.0.0:* LISTEN
tcp ::: :::* LISTEN
/data #
/data # redis-cli
127.0.0.1:> KEYS *
(empty list or set)
127.0.0.1:>
127.0.0.1:> SELECT
OK
127.0.0.1:[]> exit
/data #
/data # exit
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker run --name redis01 -d redis:4-alpine #启动一个redis容器,注意:如果镜像不存在他会自动去官网下载对应的镜像哟~
10>.docker rm(删除一个或多个容器,该命令等效于"docker container rm")
[root@node101.yinzhengjie.org.cn ~]# docker rm --help #查看该命令的帮助信息 Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] Remove one or more containers Options:
-f, --force Force the removal of a running container (uses SIGKILL)
-l, --link Remove the specified link
-v, --volumes Remove the volumes associated with the container
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker rm --help #查看该命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS N
AMEScb5fb9d1adc7 busybox:latest "sh" minutes ago Exited () About a minute ago b
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker rm b1 #删除指定容器
b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker rm b1 #删除指定容器b1
11>.docker pause(暂停一个或多个容器,该命令等效于"docker container pause")
12>.docker unpause(取消暂停一个或多个容器,该命令等效于"docker container unpause")
13>.docker top(显示容器运行的进程信息,可用查看出哪些容器更耗资源,该命令等效于"docker container top")
[root@node101.yinzhengjie.org.cn ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b16c5b671f31 redis:-alpine "docker-entrypoint.s…" minutes ago Up minutes /tcp redis01
ce713ceaa586 nginx:1.14-alpine "nginx -g 'daemon of…" minutes ago Up minutes /tcp web01
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker top web01 #查看web01容器的进程信息
UID PID PPID C STIME TTY TIME
CMDroot : ? ::
nginx: master process nginx -g daemon off; : ? ::
nginx: worker process[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker top web01 #查看web01容器的进程信息
14>.docker container ls(列出已有容器,等效于"docker container ps")
[root@node101.yinzhengjie.org.cn ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b16c5b671f31 redis:-alpine "docker-entrypoint.s…" minutes ago Up minutes /tcp redis01
ce713ceaa586 nginx:1.14-alpine "nginx -g 'daemon of…" minutes ago Up minutes /tcp web01
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container ls
[root@node101.yinzhengjie.org.cn ~]# docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b16c5b671f31 redis:-alpine "docker-entrypoint.s…" minutes ago Up minutes /tcp redis01
ce713ceaa586 nginx:1.14-alpine "nginx -g 'daemon of…" minutes ago Up minutes /tcp web01
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container ps
15>.docker ps(显示所有容器进程,等效于"docker container ps",推荐使用"docker container ls")
[root@node101.yinzhengjie.org.cn ~]# docker ps --help #查看该命令的帮助信息 Usage: docker ps [OPTIONS] List containers Options:
-a, --all Show all containers (default shows just running)
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print containers using a Go template
-n, --last int Show n last created containers (includes all states) (default -)
-l, --latest Show the latest created container (includes all states)
--no-trunc Don't truncate output
-q, --quiet Only display numeric IDs
-s, --size Display total file sizes
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker ps --help #查看该命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker ps #查看运行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb5fb9d1adc7 busybox:latest "sh" minutes ago Up minutes b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker ps #查看运行的容器
16>.docker network(网络管理命令)
[root@node101.yinzhengjie.org.cn ~]# docker network --help #查看该命令的帮助信息 Usage: docker network COMMAND Manage networks 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.
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker network --help #查看该命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker network ls #查看可用的网络
NETWORK ID NAME DRIVER SCOPE
c2802fc2d2c3 bridge bridge local
9f539144f682 host host local
e10670abb710 none null local
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker network ls #查看可用的网络
17>.docker inspect(获取指定容器/镜像的元数据信息,该命令等效于"docker container inspect")
[root@node101.yinzhengjie.org.cn ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb5fb9d1adc7 busybox:latest "sh" minutes ago Up minutes b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker inspect b1 #获取指定容器的元数据信息
[
{
"Id": "cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15",
"Created": "2019-10-16T22:58:31.841469017Z",
"Path": "sh",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": ,
"ExitCode": ,
"Error": "",
"StartedAt": "2019-10-16T22:58:32.33407354Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:19485c79a9bbdca205fce4f791efeaa2a103e23431434696cc54fdd939e9198d",
"ResolvConfPath": "/var/lib/docker/containers/cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15/hostname",
"HostsPath": "/var/lib/docker/containers/cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15/hosts",
"LogPath": "/var/lib/docker/containers/cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15/cb5fb9d1adc74e1aed93e48
cf463e8f92c5af2e2a08d06a21c668bd12818dd15-json.log", "Name": "/b1",
"RestartCount": ,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount":
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": ,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": ,
"Runtime": "runc",
"ConsoleSize": [
, ],
"Isolation": "",
"CpuShares": ,
"Memory": ,
"NanoCpus": ,
"CgroupParent": "",
"BlkioWeight": ,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": ,
"CpuQuota": ,
"CpuRealtimePeriod": ,
"CpuRealtimeRuntime": ,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": ,
"KernelMemoryTCP": ,
"MemoryReservation": ,
"MemorySwap": ,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": ,
"CpuPercent": ,
"IOMaximumIOps": ,
"IOMaximumBandwidth": ,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/8fc38355b69e4f7e15dbbdaae09e14bbee4fa8f64507b0ba66d91d7ac7a94f2f-init/diff:/var/l
ib/docker/overlay2/b770b052c1df66b22f2bbc171e637e15b1cc3ff49b4ae3eca3d32f5ad1b778d3/diff", "MergedDir": "/var/lib/docker/overlay2/8fc38355b69e4f7e15dbbdaae09e14bbee4fa8f64507b0ba66d91d7ac7a94f2f/merged",
"UpperDir": "/var/lib/docker/overlay2/8fc38355b69e4f7e15dbbdaae09e14bbee4fa8f64507b0ba66d91d7ac7a94f2f/diff",
"WorkDir": "/var/lib/docker/overlay2/8fc38355b69e4f7e15dbbdaae09e14bbee4fa8f64507b0ba66d91d7ac7a94f2f/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "cb5fb9d1adc7",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"sh"
],
"Image": "busybox:latest",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "00e83dbc6f6c139b185206915c601d27d443766de99bda6d643ca6b3ebd76604",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": ,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/00e83dbc6f6c",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "2038c26a11ee7376bf03d0dc5d60aab0b2f0519d3098f7413d25a099aea4bf49",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": ,
"IPAddress": "172.17.0.2",
"IPPrefixLen": ,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "c2802fc2d2c3198bd6d5257cb83043aabd76e3ecaeea8daafe1b0bb065efb9d4",
"EndpointID": "2038c26a11ee7376bf03d0dc5d60aab0b2f0519d3098f7413d25a099aea4bf49",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": ,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": ,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker inspect b1 #获取指定容器的元数据信息
[root@node101.yinzhengjie.org.cn ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb5fb9d1adc7 busybox:latest "sh" minutes ago Up minutes b1
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container inspect b1 #获取指定容器的元数据信息
[
{
"Id": "cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15",
"Created": "2019-10-16T22:58:31.841469017Z",
"Path": "sh",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": ,
"ExitCode": ,
"Error": "",
"StartedAt": "2019-10-16T22:58:32.33407354Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:19485c79a9bbdca205fce4f791efeaa2a103e23431434696cc54fdd939e9198d",
"ResolvConfPath": "/var/lib/docker/containers/cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15/hostname",
"HostsPath": "/var/lib/docker/containers/cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15/hosts",
"LogPath": "/var/lib/docker/containers/cb5fb9d1adc74e1aed93e48cf463e8f92c5af2e2a08d06a21c668bd12818dd15/cb5fb9d1adc74e1aed93e48
cf463e8f92c5af2e2a08d06a21c668bd12818dd15-json.log", "Name": "/b1",
"RestartCount": ,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount":
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": ,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": ,
"Runtime": "runc",
"ConsoleSize": [
, ],
"Isolation": "",
"CpuShares": ,
"Memory": ,
"NanoCpus": ,
"CgroupParent": "",
"BlkioWeight": ,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": ,
"CpuQuota": ,
"CpuRealtimePeriod": ,
"CpuRealtimeRuntime": ,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": ,
"KernelMemoryTCP": ,
"MemoryReservation": ,
"MemorySwap": ,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": ,
"CpuPercent": ,
"IOMaximumIOps": ,
"IOMaximumBandwidth": ,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/8fc38355b69e4f7e15dbbdaae09e14bbee4fa8f64507b0ba66d91d7ac7a94f2f-init/diff:/var/l
ib/docker/overlay2/b770b052c1df66b22f2bbc171e637e15b1cc3ff49b4ae3eca3d32f5ad1b778d3/diff", "MergedDir": "/var/lib/docker/overlay2/8fc38355b69e4f7e15dbbdaae09e14bbee4fa8f64507b0ba66d91d7ac7a94f2f/merged",
"UpperDir": "/var/lib/docker/overlay2/8fc38355b69e4f7e15dbbdaae09e14bbee4fa8f64507b0ba66d91d7ac7a94f2f/diff",
"WorkDir": "/var/lib/docker/overlay2/8fc38355b69e4f7e15dbbdaae09e14bbee4fa8f64507b0ba66d91d7ac7a94f2f/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "cb5fb9d1adc7",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"sh"
],
"Image": "busybox:latest",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "00e83dbc6f6c139b185206915c601d27d443766de99bda6d643ca6b3ebd76604",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": ,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/00e83dbc6f6c",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "2038c26a11ee7376bf03d0dc5d60aab0b2f0519d3098f7413d25a099aea4bf49",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": ,
"IPAddress": "172.17.0.2",
"IPPrefixLen": ,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "c2802fc2d2c3198bd6d5257cb83043aabd76e3ecaeea8daafe1b0bb065efb9d4",
"EndpointID": "2038c26a11ee7376bf03d0dc5d60aab0b2f0519d3098f7413d25a099aea4bf49",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": ,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": ,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container inspect b1 #获取指定容器的元数据信息
18>.docker exec(在运行中的容器运行命令,该命令等效于"docker container exec")
[root@node101.yinzhengjie.org.cn ~]# docker exec --help #查看该命令的帮助信息 Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in a running container Options:
-d, --detach Detached mode: run command in the background
--detach-keys string Override the key sequence for detaching a container
-e, --env list Set environment variables
-i, --interactive Keep STDIN open even if not attached
--privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container exec --help Usage: docker container exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in a running container Options:
-d, --detach Detached mode: run command in the background
--detach-keys string Override the key sequence for detaching a container
-e, --env list Set environment variables
-i, --interactive Keep STDIN open even if not attached
--privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker exec --help #查看该命令的帮助信息
[root@node101.yinzhengjie.org.cn ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b16c5b671f31 redis:-alpine "docker-entrypoint.s…" seconds ago Up seconds /tcp redis01
ce713ceaa586 nginx:1.14-alpine "nginx -g 'daemon of…" minutes ago Up minutes /tcp web01
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container exec -it redis01 /bin/sh #注意,-i表示启用交互式,-t表示启动一个终端,解释器类型不支持/bin/bash,因此我们这里需要使用"/bin/sh"
/data #
/data # ps
PID USER TIME COMMAND
redis : redis-server
root : /bin/sh
root : ps
/data #
/data #
/data # netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0.0.0.0: 0.0.0.0:* LISTEN
tcp ::: :::* LISTEN
/data #
/data # redis-cli
127.0.0.1:> KEYS *
(empty list or set)
127.0.0.1:>
127.0.0.1:> SELECT
OK
127.0.0.1:[]> exit
/data #
/data # exit
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container exec -it redis01 /bin/sh #注意,-i表示启用交互式,-t表示启动一个终端,解释器类型不支持/bin/bash,因此我们这里需要使用"/bin/sh"
19>.docker logs(获取容器的log信息,该命令等效于"docker container logs")
[root@node101.yinzhengjie.org.cn ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b16c5b671f31 redis:-alpine "docker-entrypoint.s…" minutes ago Up minutes /tcp redis01
ce713ceaa586 nginx:1.14-alpine "nginx -g 'daemon of…" minutes ago Up minutes /tcp web01
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container logs web01 #显示web01容器的日志信息
172.17.0.1 - - [/Oct/::: +] "GET / HTTP/1.1" "-" "curl/7.29.0" "-"
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# docker container logs web01 #显示web01容器的日志信息
20>.
三.docker event state(docker命令的状态转换关系)
Docker基础用法篇的更多相关文章
- docker第二篇 Docker基础用法
Docker中的容器 lxc -> libcontainer -> runC OCI (Open Container Initiative) 由Linux基金会主导于2015年6月创立 作 ...
- Docker 学习2 Docker基础用法
一.docker架构 1.client端 2.server端,docker daemo守护进程,监听在套接字之上.docker支持三种类型套接字. a.ip vs套接字:即IP + 端口套接字 b.i ...
- 2、Docker基础用法
容器镜像:https://hub.docker.com/ Docker架构图: https://ruby-china.org/topics/22004 Docker使用客户端-服务器(client- ...
- 2.docker基础用法
一.前言 OCI(Open Container Initiative):由Linux基金会主导于2015年6月创立,OCI定义了容器运行时的标准. OCI有两部分组成: the Runtime Spe ...
- docker基础用法
docker 架构: docker 安装前期准备: 安装centos7 ,不要在centos6 [root@node01 yum.repos.d]# uname -a Linux node01 -. ...
- Docker基础教程
一.Docker是什么? KVM, Virtualbox, Vmware是虚拟出机器,让每个实例看到一个单独的机器:而Docker是虚拟出操作系统,实现应用之间的隔离,让各个应用觉得自己有一个自己的操 ...
- Docker 安装和基础用法
理解Docker(1):Docker 安装和基础用法 本系列文章将介绍Docker的有关知识: (1)Docker 安装及基本用法 (2)Docker 镜像 (3)Docker 容器的隔离性 - 使用 ...
- 精讲响应式webclient第1篇-响应式非阻塞IO与基础用法
笔者在之前已经写了一系列的关于RestTemplate的文章,如下: 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用 精讲RestTemplate第2篇-多种底层HT ...
- Docker基础与实战,看这一篇就够了
docker 基础 什么是Docker Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核的 cgroup,namespace,以及 AUFS 类的 Uni ...
随机推荐
- linux默认的2.7升级到3.7版本
CentOS7中自带的python版本是python-2.7.5,由于新开的虚拟机需要使用python3,于是便升级一下版本. 安装Python3.7.3 官网下载地址:https://www.pyt ...
- 解决IDEA打Jar包找不到或无法加载主类问题
转自以下博主内容:https://blog.csdn.net/qq_43189115/article/details/99856659 就是因为打包一直提示有问题,网上很多帖子试过没有用,就是这个博主 ...
- microsoft vs code 绿化
下载地址: https://code.visualstudio.com/#alt-downloads 各个版本比较 User Installer System Installer .zip resou ...
- EasyNVR摄像机网页无插件直播方案H5前端构建之:bootstrap弹窗功能的实现方案与代码
前言介绍 在web前端的网页设计中,为了展示出简洁的网页风格和美观的效果,往往会使用弹窗效果在EasyNVR前端页面录像检索功能时,必然会播放录像,如果单独为播放录像文件排一个界面,用户在使用上会更加 ...
- phpspreadsheet 中文文档(六)读写文件+读取文件
2019年10月11日14:05:58 读写文件 从体系结构您已经知道,使用基本PhpSpreadsheet类无法对持久性存储进行读写.为此,PhpSpreadsheet提供读者和作家,这是实现\Ph ...
- 【论文阅读】3DMM-A Morphable Model for The Synthesis of 3D Faces
前言 参考 1. 2. 完
- [QT] - 图片查看器(数码相框)#工程源码
简介: 大学期间弄的一个小软件,当时是将该软件移植到嵌入式开发板使用的,软件的几个功能截图如正文所示,文末提供工程源码文件,感谢支持! 功能截图: [ 打开软件 ] [ 打开图片 ] [ 图片可放大. ...
- List集合分批多线程处理,同时控制最大并发
业务中,要实现数据日终同步,采用将同步文件中的数据封装成List集合分批处理加多线程的方式,根据数据量动态设置线程数,同时控制最大并发数量(业务中有IO操作,避免过大并发导致堵塞),实现效率提高 // ...
- Ubuntu18.04LTS python3.6 cuda10.0 下安装低版本的pytorch
Ubuntu18.04LTS python3.6 cuda10.0 下安装低版本的pytorch,运行Hypergraph Neural Networks(HGNN) https://github.c ...
- DRF框架(五)——context传参,二次封装Response类,两个视图基类(APIView/GenericAPIView),视图扩展类(mixins),子类视图(工具视图),视图集(viewsets),工具视图集
复习 1.整体修改与局部修改 # 序列化get (给前端传递参数) #查询 ser_obj = ModelSerializer(model_obj) #只传递一个参数,默认是instance的参数,查 ...