Docker学习笔记二
作者:朱金灿
来源:https://blog.csdn.net/clever101
今天继续学习Docker。边学边干是学习的最好方法。现在我以在centos环境上建一个ubuntu容器为例来介绍Docker的一些基本命令。
- 运行Docker命令搜索ubuntu的镜像下载网站:
# docker search ubuntu
然后我们选择一个STARS最多的进行下载,运行命令:
# docker pull Ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
f476d66f5408: Pull complete
8882c27f669e: Pull complete
d9af21273955: Pull complete
f5029279ec12: Pull complete
Digest: sha256:d26d529daa4d8567167181d9d569f2a85da3c5ecaf539cace2c6223355d69981
Status: Downloaded newer image for ubuntu:latest
下载完后运行命令安装镜像,先列出所有的镜像:
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest d131e0fa2585 2 days ago 102MB
再安装镜像:
# docker run -itd d131e0fa2585 /bin/bash
623a9fd33b9c32dc407689984d72a0056d502746e7daff94a13e70373f4d2229
其中d131e0fa2585为指定的镜像ID。
到此时ubuntu容器建好了,我们进去这个容器看一下:
# docker attach 623a9fd33b9c32dc407689984d72a0056d502746e7daff94a13e70373f4d2229
这里623a9fd33b9c32dc407689984d72a0056d502746e7daff94a13e70373f4d2229是创建容器后终端返回的一串字符串。
我们查看一下ubuntu容器的版本和内核版本:
[email protected]:/# cat /etc/issue
Ubuntu 18.04.2 LTS \n \l
[email protected]:/# uname -a
Linux 623a9fd33b9c 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
最后我们按ctrl+d 退出容器且关闭容器。