拉取平台映像
docker pull centos
默认会拉取最新的版本
查看本地映像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos latest a8493f5f50ff 3 weeks ago 192.5 MB
运行Docker容器
docker run -i -t --rm centos cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 ec4c596451dd
--rm Automatically remove the container when it exits
查看所有的容器
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0c3330056886 centos "bash" About a minute ago Exited (0) 3 seconds ago condescending_varahamihira
-a 选项会显示系统所有的容器,包括正在运行的和已经停止的。
查看基本信息
docker info
在基础容器中安装httpd
docker run -i centos bash -c "yum install -y httpd;yum clean all"
查看最近一次运行的容器
docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
66ddf21f3e09 centos "bash -c 'yum install" About a minute ago Exited (0) 22 seconds ago jovial_bose
创建新映像
docker commit -m "centos + httpd" jovial_bose centos_httpd
sha256:a640a7c168fbe39f1d46ff8bb61c21a699ec575e7f2ac1cc41aa1abc12410885
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos_httpd latest a640a7c168fb 13 seconds ago 244.8 MB
<none> <none> 58e770974bf5 32 seconds ago 244.8 MB
docker.io/centos latest a8493f5f50ff 3 weeks ago 192.5 MB
基于新映像启动httpd
docker run -p 8080:80 -d centos_httpd /usr/sbin/httpd -DFOREGROUND
curl http://localhost:8080
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Apache HTTP Server Test Page powered by CentOS</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
...
查看映像的提交日志
docker history centos_httpd
IMAGE CREATED CREATED BY SIZE COMMENT
a640a7c168fb 7 minutes ago bash -c yum install -y httpd;yum clean all 52.34 MB centos + httpd
a8493f5f50ff 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
网友评论