docker基础之二搭建实验环境
环境选择:
内核
uname -r 3.10.0-957.el7.x86_64
系统
cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
源
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum install docker-ce
配置阿里镜像加速
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://i5vp5biq.mirror.aliyuncs.com"]
}
启动
systemctl start docker
测试hello-world
docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
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 host节点
docker image ls hello-world REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest fce289e99eb9 7 months ago 1.84kB
查看docker host上运行的容器
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
或docker container ls
查看docker host上所有状态的容器
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2af23ccba8b6 hello-world "/hello" 5 minutes ago Exited (0) 5 minutes ago jovial_babbage
或docker container ls -a
发现状态为Exited?
这是由于容器的生命周期与容器启动时所运行的程序有关,程序执行结束,即exited状态
运行第一个容器
docker run -d -p 80:80 httpd Unable to find image 'httpd:latest' locally latest: Pulling from library/httpd f5d23c7fed46: Pull complete b083c5fd185b: Pull complete bf5100a89e78: Pull complete 98f47fcaa52f: Pull complete 622a9dd8cfed: Pull complete Digest: sha256:dc4c86bc90593c6e4c5b06872a7a363fc7d4eec99c5d6bfac881f7371adcb2c4 Status: Downloaded newer image for httpd:latest e73baa43840a78ab1489804f20ba10e4b4f6e53bb519d9d2492365bc9d3128e6 [root@nas5 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e73baa43840a httpd "httpd-foreground" 6 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp clever_maxwell [root@nas5 ~]# docker port clever_maxwell 80/tcp -> 0.0.0.0:80 netstat -tnlp |grep :80 tcp6 0 0 :::80 :::* LISTEN 52038/docker-proxy
docker inspect clever_maxwell
[
{
"Id": "e73baa43840a78ab1489804f20ba10e4b4f6e53bb519d9d2492365bc9d3128e6",
"Created": "2019-07-29T02:14:28.746024176Z",
"Path": "httpd-foreground",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 52122,
"ExitCode": 0,
"Error": "",
"StartedAt": "2019-07-29T02:14:29.915889413Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:ee39f68eb241fd811887da7e21425ac657074363daa9969b9519504785f5d60d",
"ResolvConfPath": "/var/lib/docker/containers/e73baa43840a78ab1489804f20ba10e4b4f6e53bb519d9d2492365bc9d3128e6/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/e73baa43840a78ab1489804f20ba10e4b4f6e53bb519d9d2492365bc9d3128e6/hostname",
"HostsPath": "/var/lib/docker/containers/e73baa43840a78ab1489804f20ba10e4b4f6e53bb519d9d2492365bc9d3128e6/hosts",
"LogPath": "/var/lib/docker/containers/e73baa43840a78ab1489804f20ba10e4b4f6e53bb519d9d2492365bc9d3128e6/e73baa43840a78ab1489804f20ba10e4b4f6e53bb519d9d2492365bc9d3128e6-json.log",
"Name": "/clever_maxwell",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "80"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"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,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"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/deb4aefe4017d1fe67576730d10882fb808b52b520fbf1b68e7df6cb0b3245ae-init/diff:/var/lib/docker/overlay2/c5cc525148310472b925ca2f7fa9b1a431205346e1110c15bb135e1fcdbf3c0f/diff:/var/lib/docker/overlay2/490b5ac074374d35e4426f439f4edb1ef8eb4b7d36d2802f278c1414ca9f2f44/diff:/var/lib/docker/overlay2/4152a9f7537fbb4fcacbe7b789304704a0d046b0df2ebbf2ec45cfc911eb76b4/diff:/var/lib/docker/overlay2/12e13e8e4a4fd9832c1b0f7650e3d768f5d1fa2ac163e26bc02d6d7918c543bd/diff:/var/lib/docker/overlay2/f3c853feeb71177b58a5064449ad2e2c9a24ca1d3b0727f97419a553f5526c57/diff",
"MergedDir": "/var/lib/docker/overlay2/deb4aefe4017d1fe67576730d10882fb808b52b520fbf1b68e7df6cb0b3245ae/merged",
"UpperDir": "/var/lib/docker/overlay2/deb4aefe4017d1fe67576730d10882fb808b52b520fbf1b68e7df6cb0b3245ae/diff",
"WorkDir": "/var/lib/docker/overlay2/deb4aefe4017d1fe67576730d10882fb808b52b520fbf1b68e7df6cb0b3245ae/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "e73baa43840a",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/apache2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"HTTPD_PREFIX=/usr/local/apache2",
"HTTPD_VERSION=2.4.39",
"HTTPD_SHA256=b4ca9d05773aa59b54d66cd8f4744b945289f084d3be17d7981d1783a5decfa2",
"HTTPD_PATCHES="
],
"Cmd": [
"httpd-foreground"
],
"Image": "httpd",
"Volumes": null,
"WorkingDir": "/usr/local/apache2",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "84db26d88c0c4cbe93c7e8549e3936e137aee148e4fd210177b4cfd015da5b01",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
}
]
},
"SandboxKey": "/var/run/docker/netns/84db26d88c0c",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "5df947d9388e12188f49a940fe096afd1b4dfa51af1cdce66dfc943d9ee10f53",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "6444736e5856f5e4ffe462e3a243fc5fe1255464ccfaafcfe0ef38151ff4a633",
"EndpointID": "5df947d9388e12188f49a940fe096afd1b4dfa51af1cdce66dfc943d9ee10f53",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]

浙公网安备 33010602011771号