$ docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
OPTIONS:
- -i: –interactive 采用交互式创建容器
- -t: –tty 为容器提供终端
如果以单次执行方式运行容器,当命令执行完毕后容器就会自动停止。而使用交互的方式运行容器,则直到交互程序退出容器才会停止。
schen@scvmu01:~$ docker run ubuntu echo 'hello world'
hello world
schen@scvmu01:~$
schen@scvmu01:~$ docker run -i -t ubuntu /bin/bash
root@76d304bc27eb:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 2 12:40 ? 00:00:00 /bin/bash
root 10 1 0 12:40 ? 00:00:00 ps -ef
root@76d304bc27eb:/# exit
exit
schen@scvmu01:~$
查看当前正在运行的容器,可以输入不带参数的docker ps
命令,查看所有容器使用-a
选项,查看最后执行的容器使用-l
选项:
$ docker ps [OPTIONS]
schen@scvmu01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
schen@scvmu01:~$
schen@scvmu01:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76d304bc27eb ubuntu "/bin/bash" About a minute ago Exited (0) About a minute ago trusting_keller
c408a62d943c ubuntu "echo 'hello world'" 4 minutes ago Exited (0) 4 minutes ago sad_hodgkin
2d85b99b03b2 ubuntu "echo 'Hello world'" 21 hours ago Exited (0) 21 hours ago nostalgic_pasteur
schen@scvmu01:~$
schen@scvmu01:~$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76d304bc27eb ubuntu "/bin/bash" About a minute ago Exited (0) About a minute ago
schen@scvmu01:~$
检查某一特定容器可以使用docker inspect
命令,后面跟容器的名称或唯一ID。
$ docker inspect [OPTIONS] CONTAINER|IMAGE|TASK [CONTAINER|IMAGE|TASK...]
Docker自动创建的容器名称同样是不方便记忆的,但我们可以在运行容器时使用--name
参数为其指定一个名称,命令格式为docker run --name=
。
schen@scvmu01:~$ docker inspect 76d304bc27eb
[
{
"Id": "76d304bc27ebd2669c9564f3482e435b8c8d25c17f93f0199ce873dc7e741647",
"Created": "2016-08-31T12:40:17.751824541Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 0,
"Error": "",
"StartedAt": "2016-08-31T12:40:21.088106155Z",
"FinishedAt": "2016-08-31T12:40:30.460471528Z"
},
"Image": "sha256:bd3d4369aebc4945be269859df0e15b1d32fefa2645f5699037d7d8c6b415a10",
"ResolvConfPath": "/var/lib/docker/containers/76d304bc27ebd2669c9564f3482e435b8c8d25c17f93f0199ce873dc7e741647/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/76d304bc27ebd2669c9564f3482e435b8c8d25c17f93f0199ce873dc7e741647/hostname",
"HostsPath": "/var/lib/docker/containers/76d304bc27ebd2669c9564f3482e435b8c8d25c17f93f0199ce873dc7e741647/hosts",
"LogPath": "/var/lib/docker/containers/76d304bc27ebd2669c9564f3482e435b8c8d25c17f93f0199ce873dc7e741647/76d304bc27ebd2669c9564f3482e435b8c8d25c17f93f0199ce873dc7e741647-json.log",
"Name": "/trusting_keller",
"RestartCount": 0,
"Driver": "aufs",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Name": "aufs",
"Data": null
},
"Mounts": [],
"Config": {
"Hostname": "76d304bc27eb",
"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": [
"/bin/bash"
],
"Image": "ubuntu",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "0dda5fc7ea2e02c734614254bc2a3573d02915924dff5bd728729316cede7371",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": null,
"SandboxKey": "/var/run/docker/netns/0dda5fc7ea2e",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "15eca23f0c8412855e33d8b4bcbc1b2fc01cd1a0f7c8c730c22baf7b5591bbfb",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": ""
}
}
}
}
]
schen@scvmu01:~$
不一定每次都要创建新的容器,Docker可以为我们启动已经停止的容器。
$ docker start [OPTIONS] CONTAINER [CONTAINER...]
schen@scvmu01:~$ docker start -i 76d304bc27eb
root@76d304bc27eb:/# exit
exit
schen@scvmu01:~$
$ docker rm [OPTIONS] CONTAINER [CONTAINER...]
schen@scvmu01:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76d304bc27eb ubuntu "/bin/bash" 17 minutes ago Exited (0) 49 seconds ago trusting_keller
c408a62d943c ubuntu "echo 'hello world'" 20 minutes ago Exited (0) 20 minutes ago sad_hodgkin
2d85b99b03b2 ubuntu "echo 'Hello world'" 22 hours ago Exited (0) 22 hours ago nostalgic_pasteur
schen@scvmu01:~$
schen@scvmu01:~$ docker rm 2d85b99b03b2
2d85b99b03b2
schen@scvmu01:~$
schen@scvmu01:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76d304bc27eb ubuntu "/bin/bash" 17 minutes ago Exited (0) About a minute ago trusting_keller
c408a62d943c ubuntu "echo 'hello world'" 20 minutes ago Exited (0) 20 minutes ago sad_hodgkin
schen@scvmu01:~$
守护式容器,提供一个可以长时间运行的容器,它没有交互式的对话,非常适合运行应用程序和服务。
在交互式容器中,先按
再按
,即可将容器切换到后台。
schen@scvmu01:~$ docker start -i 76d304bc27eb
root@76d304bc27eb:/#
root@76d304bc27eb:/# schen@scvmu01:~$
schen@scvmu01:~$
schen@scvmu01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76d304bc27eb ubuntu "/bin/bash" 49 minutes ago Up 18 seconds trusting_keller
schen@scvmu01:~$
$ docker attach [OPTIONS] CONTAINER
schen@scvmu01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76d304bc27eb ubuntu "/bin/bash" 51 minutes ago Up 2 minutes trusting_keller
schen@scvmu01:~$
schen@scvmu01:~$ docker attach 76d304bc27eb
root@76d304bc27eb:/#
root@76d304bc27eb:/#
可以通过使用docker run
命令的-d
参数来直接启动守护式容器。
schen@scvmu01:~$ docker run --name dc01 -d ubuntu /bin/bash -c "while true; do date; sleep 1; done"
0715b5e7fefad83ee4133a279034f211bae5c802a0006050c6e80ce0c13a8732
schen@scvmu01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0715b5e7fefa ubuntu "/bin/bash -c 'while " 28 seconds ago Up 25 seconds dc01
可以通过使用docker logs
命令来查看容器的运行日志,其中--tail
选项可以指定查看最后几条日志,而-t
选项则可以对日志条目附加时间戳。使用-f
选项可以跟踪日志的输出,直到手动停止。
$ docker logs [OPTIONS] CONTAINER
schen@scvmu01:~$ docker logs --tail=10 dc01
Wed Aug 31 13:41:46 UTC 2016
Wed Aug 31 13:41:47 UTC 2016
Wed Aug 31 13:41:48 UTC 2016
Wed Aug 31 13:41:49 UTC 2016
Wed Aug 31 13:41:50 UTC 2016
Wed Aug 31 13:41:51 UTC 2016
Wed Aug 31 13:41:52 UTC 2016
Wed Aug 31 13:41:53 UTC 2016
Wed Aug 31 13:41:54 UTC 2016
Wed Aug 31 13:41:55 UTC 2016
schen@scvmu01:~$
schen@scvmu01:~$ docker logs -t --tail=10 dc01
2016-08-31T13:41:53.554214527Z Wed Aug 31 13:41:53 UTC 2016
2016-08-31T13:41:54.590200900Z Wed Aug 31 13:41:54 UTC 2016
2016-08-31T13:41:55.611758596Z Wed Aug 31 13:41:55 UTC 2016
2016-08-31T13:41:56.630210664Z Wed Aug 31 13:41:56 UTC 2016
2016-08-31T13:41:57.650903289Z Wed Aug 31 13:41:57 UTC 2016
2016-08-31T13:41:58.675035219Z Wed Aug 31 13:41:58 UTC 2016
2016-08-31T13:41:59.700127264Z Wed Aug 31 13:41:59 UTC 2016
2016-08-31T13:42:00.722263547Z Wed Aug 31 13:42:00 UTC 2016
2016-08-31T13:42:01.746876606Z Wed Aug 31 13:42:01 UTC 2016
2016-08-31T13:42:02.793220275Z Wed Aug 31 13:42:02 UTC 2016
schen@scvmu01:~$
schen@scvmu01:~$ docker logs -tf --tail=10 dc01
2016-08-31T13:42:09.015637533Z Wed Aug 31 13:42:09 UTC 2016
2016-08-31T13:42:10.044347857Z Wed Aug 31 13:42:10 UTC 2016
2016-08-31T13:42:11.078681070Z Wed Aug 31 13:42:11 UTC 2016
2016-08-31T13:42:12.111914908Z Wed Aug 31 13:42:12 UTC 2016
2016-08-31T13:42:13.150606884Z Wed Aug 31 13:42:13 UTC 2016
2016-08-31T13:42:14.189534719Z Wed Aug 31 13:42:14 UTC 2016
2016-08-31T13:42:15.221374110Z Wed Aug 31 13:42:15 UTC 2016
2016-08-31T13:42:16.255888600Z Wed Aug 31 13:42:16 UTC 2016
2016-08-31T13:42:17.294017584Z Wed Aug 31 13:42:17 UTC 2016
2016-08-31T13:42:18.322381829Z Wed Aug 31 13:42:18 UTC 2016
2016-08-31T13:42:19.360735491Z Wed Aug 31 13:42:19 UTC 2016
2016-08-31T13:42:20.436246759Z Wed Aug 31 13:42:20 UTC 2016
^C
$ docker top CONTAINER [ps OPTIONS]
schen@scvmu01:~$ docker top dc01
UID PID PPID C STIME TTY TIME CMD
root 20646 20618 0 21:37 ? 00:00:04 /bin/bash -c while true; do date; sleep 1; done
root 22536 20646 0 21:53 ? 00:00:00 sleep 1
schen@scvmu01:~$
虽然Docker鼓励我们一个容器只运行一个服务,但是当我们需要对运行中的容器进行监控、维护和管理时,通常需要为运行中的容器启动新进程。
$ docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
这条命令与docker run
极为相似,也可以使用-i
、-t
和-d
等参数。
schen@scvmu01:~$ docker exec -i -t dc01 /bin/bash
root@0715b5e7fefa:/#
root@0715b5e7fefa:/# schen@scvmu01:~$
schen@scvmu01:~$
schen@scvmu01:~$ docker top dc01
UID PID PPID C STIME TTY TIME CMD
root 20646 20618 0 21:37 ? 00:00:07 /bin/bash -c while true; do date; sleep 1; done
root 23592 23578 0 22:01 pts/1 00:00:00 /bin/bash
root 23795 20646 0 22:03 ? 00:00:00 sleep 1
schen@scvmu01:~$
$ docker stop [OPTIONS] CONTAINER [CONTAINER...]
$ docker kill [OPTIONS] CONTAINER [CONTAINER...]
它们的区别在于docker stop
命令向容器发送一个信号,等待容器自行终止,而docker kill
命令则会直接停止容器。
schen@scvmu01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0715b5e7fefa ubuntu "/bin/bash -c 'while " 31 minutes ago Up 31 minutes dc01
schen@scvmu01:~$
schen@scvmu01:~$ docker run --name dc02 -d ubuntu /bin/bash -c "while true; do date; sleep 1; done"
10812788760fab0eb57fb82876942a47e89d73f1c687ca485c316d0b3d177556
schen@scvmu01:~$
schen@scvmu01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
10812788760f ubuntu "/bin/bash -c 'while " 4 seconds ago Up 2 seconds dc02
0715b5e7fefa ubuntu "/bin/bash -c 'while " 31 minutes ago Up 31 minutes dc01
schen@scvmu01:~$
schen@scvmu01:~$ docker stop dc01
dc01
schen@scvmu01:~$
schen@scvmu01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
10812788760f ubuntu "/bin/bash -c 'while " 36 seconds ago Up 35 seconds dc02
schen@scvmu01:~$
schen@scvmu01:~$ docker kill dc02
dc02
schen@scvmu01:~$
schen@scvmu01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
schen@scvmu01:~$
在容器中通过Nginx创建静态网站的大致步骤:
1. 创建映射80端口的交互式容器
2. 安装Nginx
3. 安装文本编辑器vim
4. 创建静态页面
5. 修改Nginx配置文件
6. 运行Nginx
7. 验证网站访问
服务器对外提供服务需要暴露端口,这个过程在docker中可以通过docker run
命令的两个参数来完成:-P
映射所有打开的端口,-p
则只映射指定的端口。
映射指定端口有如下四种格式:
- 命令docker run -p 80 -i -t ubuntu /bin/bash
仅指定容器端口,这种情况下宿主机的端口是随机映射的;
- 命令docker run -p 8080:80 -i -t ubuntu /bin/bash
同时指定了宿主机和容器的端口,这样的映射是一一对应的;
- 命令docker run -p 0.0.0.0:80 -i -t ubuntu /bin/bash
指定了容器的IP地址和端口,宿主机的端口将是随机映射的;
- 命令docker run -p 0.0.0.0:8080:80 -i -t ubuntu /bin/bash
同时指定了容器的IP地址,宿主机的端口和容器的端口;
schen@scvmu01:~$ docker run -p 80 --name web -i -t ubuntu /bin/bash
root@690de66044af:/#
root@690de66044af:/# apt-get install -y nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package nginx
root@690de66044af:/#
root@690de66044af:/# apt-get update
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]
......
Reading package lists... Done
root@690de66044af:/#
root@690de66044af:/# apt-get install -y nginx
Reading package lists... Done
Building dependency tree
......
Processing triggers for systemd (229-4ubuntu7) ...
root@690de66044af:/#
root@690de66044af:/# apt-get install -y vim
Reading package lists... Done
Building dependency tree
......
Processing triggers for libc-bin (2.23-0ubuntu3) ...
root@690de66044af:/#
root@690de66044af:/# mkdir -p /var/www/html
root@690de66044af:/#
root@690de66044af:/# cd /var/www/html
root@690de66044af:/var/www/html#
root@690de66044af:/var/www/html# vi index.html
root@690de66044af:/var/www/html#
root@690de66044af:/var/www/html# cat index.html
Nginx in Docker
Hello, I'm website in Docker!
root@690de66044af:/var/www/html#
首先使用whereis
命令确定Nginx的安装路径,然后查看default
配置文件中的“网站根目录”,如果不是我们刚刚建立的/var/www/html
则将其修改过来。
root@690de66044af:/var/www/html# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
root@690de66044af:/var/www/html#
root@690de66044af:/var/www/html# ls /etc/nginx
conf.d koi-utf nginx.conf sites-available uwsgi_params
fastcgi.conf koi-win proxy_params sites-enabled win-utf
fastcgi_params mime.types scgi_params snippets
root@690de66044af:/var/www/html#
root@690de66044af:/var/www/html# ls /etc/nginx/sites-enabled/
default
root@690de66044af:/var/www/html#
root@690de66044af:/var/www/html# vi /etc/nginx/sites-enabled/default
root@690de66044af:/var/www/html#
root@690de66044af:/var/www/html# cat /etc/nginx/sites-enabled/default | grep "root "
root /var/www/html;
# root /var/www/example.com;
root@690de66044af:/var/www/html#
回到根目录,运行Nginx,并将容器切换到后台。
root@690de66044af:/var/www/html# cd /
root@690de66044af:/#
root@690de66044af:/# nginx
root@690de66044af:/#
root@690de66044af:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 14:06 ? 00:00:00 /bin/bash
root 790 1 0 14:50 ? 00:00:00 nginx: master process ngin
www-data 791 790 0 14:50 ? 00:00:00 nginx: worker process
root 792 1 0 14:50 ? 00:00:00 ps -ef
root@690de66044af:/# schen@scvmu01:~$
schen@scvmu01:~$
我们可以使用docker ps
和docker port
命令查看到被映射的端口,使用docker top
命令我们可以查看到Nginx进程仍然在运行。
schen@scvmu01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
690de66044af ubuntu "/bin/bash" 44 minutes ago Up 44 minutes 0.0.0.0:32768->80/tcp web
schen@scvmu01:~$
schen@scvmu01:~$ docker port web
80/tcp -> 0.0.0.0:32768
schen@scvmu01:~$
schen@scvmu01:~$ docker top web
UID PID PPID C STIME TTY TIME CMD
root 1680 1664 0 22:06 pts/1 00:00:00 /bin/bash
root 2515 1680 0 22:50 ? 00:00:00 nginx: master process nginx
www-data 2516 2515 0 22:50 ? 00:00:00 nginx: worker process
schen@scvmu01:~$
使用curl
命令可以在命令行中验证网站是否可以访问,我们既可以通过宿主计算机的IP地址和端口号来访问,也可以通过容器的IP地址和端口号来访问。我们可以通过docker inspect
命令列出容器的详细信息,并查找“IPAddress”字段确定它的IP地址。
schen@scvmu01:~$ curl http://127.0.0.1:32768
<html>
<head>
<title>Nginx in Dockertitle>
head>
<body>
<h1>Hello, I'm website in Docker!h1>
body>
html>
schen@scvmu01:~$
schen@scvmu01:~$ docker inspect web | grep "IPAddress"
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
schen@scvmu01:~$
schen@scvmu01:~$ curl http://172.17.0.2
<html>
<head>
<title>Nginx in Dockertitle>
head>
<body>
<h1>Hello, I'm website in Docker!h1>
body>
html>
schen@scvmu01:~$
当然,通过浏览器验证也是完全可以的。
使用docker stop
停止容器并使用docker start
重启后,我们会发现容器中并没有Nginx进程在运行,这时候就要用到docker exec
命令,让它来帮我们启动Nginx。
schen@scvmu01:~$ docker stop web
web
schen@scvmu01:~$
schen@scvmu01:~$ docker start -i web
root@690de66044af:/#
root@690de66044af:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 1 15:30 ? 00:00:00 /bin/bash
root 9 1 0 15:30 ? 00:00:00 ps -ef
root@690de66044af:/#
root@690de66044af:/# schen@scvmu01:~$
schen@scvmu01:~$
schen@scvmu01:~$ docker exec web nginx
schen@scvmu01:~$
schen@scvmu01:~$ docker top web
UID PID PPID C STIME TTY TIME CMD
root 2683 2657 0 23:30 pts/1 00:00:00 /bin/bash
root 2742 1 0 23:32 ? 00:00:00 nginx: master process nginx
www-data 2743 2742 0 23:32 ? 00:00:00 nginx: worker process
schen@scvmu01:~$
我们通过刚才的命令验证这个网站,发现失败了。这是因为每次启动这个容器,IP地址和映射端口号都会被重新分配。我们可以使用docker inspect
命令列出容器的详细信息,并查找“IPAddress”和“HostPort”字段来确定新的IP地址和映射端口号。
schen@scvmu01:~$ curl http://127.0.0.1:32768
curl: (7) Failed to connect to 127.0.0.1 port 32768: Connection refused
schen@scvmu01:~$
schen@scvmu01:~$ docker inspect web | grep "HostPort"
"HostPort": ""
"HostPort": "32769"
schen@scvmu01:~$
schen@scvmu01:~$ curl http://127.0.0.1:32769
Nginx in Docker
<body>
Hello, I'm website in Docker!
body>
schen@scvmu01:~$
schen@scvmu01:~$ docker inspect web | grep "IPAddress"
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
schen@scvmu01:~$
schen@scvmu01:~$ curl http://172.17.0.2
Nginx in Docker
<body>
Hello, I'm website in Docker!
body>
schen@scvmu01:~$
本节介绍了Docker容器的相关知识以及命令的基本用法,关于这些命令的更多内容可以查阅官方手册,即通过man
命令查看,例如:
man docker-run
man docker-logs
man docker-top
man docker-exec
...