[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
helloworld v1 7d25a983d1cf About an hour ago 130MB
python 2.7-slim 48e3247f2a19 4 days ago 120MB
二、启动容器
通过docker run命令启动容器:
[root@localhost test]# docker run -d -p 8080:80 helloworld:v1
-p 8080:80将容器内的80端口映射在宿主机的8080端口上
容器启动后通过docker ps命令查看:
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d33c5a4a018c helloworld:v1 "python app.py" 2 minutes ago Up 2 minutes 0.0.0.0:8080->80/tcp friendly_spence
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
helloworld v1 7d25a983d1cf About an hour ago 130MB
python 2.7-slim 48e3247f2a19 4 days ago 120MB
[root@localhost ~]# docker tag 7d25a983d1cf registry.cn-shanghai.aliyuncs.com/hxt/helloworld:v1
[root@localhost ~]# docker push registry.cn-shanghai.aliyuncs.com/hxt/helloworld:v1
从Registry中拉取镜像
[root@localhost ~]# docker pull registry.cn-shanghai.aliyuncs.com/hxt/helloworld:v1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
helloworld v1 7d25a983d1cf About an hour ago 130MB
registry.cn-shanghai.aliyuncs.com/hxt/helloworld v1 7d25a983d1cf About an hour ago 130MB
python 2.7-slim 48e3247f2a19 4 days ago 120MB
Linux Namespace创建的隔离空间虽然看不见摸不着,但一个进程的Namespace信息在宿主机上是确实存在的,并且是以一个文件的方式存在
查看当前正在运行的Docker容器的进程号(PID):
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d33c5a4a018c helloworld:v1 "python app.py" About an hour ago Up 7 minutes 0.0.0.0:8080->80/tcp friendly_spence
[root@localhost ~]# docker inspect --format '{{ .State.Pid }}' d33c5a4a018c
2673
mount --bind /home/test会将/home挂载到/test上。其实相当于将/test的dentry,重定向到了/home的inode。这样当我们修改/test目录时,实际修改的是/home目录的inode。这就是为何,一旦执行umount命令,/test目录原先的内容就会恢复:因为修改真正发生在的是/home目录里