centos6 版本安装
yum install -y http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm
yum install -y docker
centos7版本安装 yum install -y docker
先启动docker服务
service docker start
docker pull centos
docker images
docker inspect id 查看详细信息 可以为id的前几位缩写
docker run -i -t ubuntu /bin/bash
使用命令docker run -i -t 镜像名字 /bin/bash创建启动一个容器,比如
docker -i -t ubuntu /bin/bash,其中使用-t参数是指定一个交互是命令行,
执行这个命令,如果本地有镜像,则用本地镜像创建一个容器,如果没有则会去docker hub下载镜像,下载时间可能有点长。
命令执行完毕后,会创建启动一个容器,并进入容器内部的shell中
方法一:如果要正常退出不关闭容器,请按Ctrl+P+Q进行退出容器
方法二:如果使用exit退出,那么在退出之后会关闭容器
docker tag docker.io/ubuntu:latest ubuntu:second 打标签 id 不会变
docker search mysql 搜索关键字为mysql的镜像 按照star数量多少排列
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu latest c9d990395902 4 days ago 113 MB
ubuntu second c9d990395902 4 days ago 113 MB
registry.docker-cn.com/library/ubuntu 14.04 3b853789146f 4 days ago 223 MB
docker.io/centos latest e934aafc2206 10 days ago 199 MB
docker rmi ubuntu:second 删除镜像
docker rmi 3b8 删除镜像
[root@localhost ~]# docker rmi ubuntu:second
Untagged: ubuntu:second
Untagged: docker.io/ubuntu@sha256:9ee3b83bcaa383e5e3b657f042f4034c92cdd50c03f73166c145c9ceaea9ba7c
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu latest c9d990395902 4 days ago 113 MB
registry.docker-cn.com/library/ubuntu 14.04 3b853789146f 4 days ago 223 MB
docker.io/centos latest e934aafc2206 10 days ago 199 MB
[root@localhost ~]# docker rmi 3b8
Untagged: registry.docker-cn.com/library/ubuntu:14.04
Untagged: registry.docker-cn.com/library/ubuntu@sha256:b92dc7814b2656da61a52a50020443223445fdc2caf1ea0c51fa38381d5608ad
Deleted: sha256:3b853789146f1f249f204a7f29573263ef3486571acb72d7fd8f13056450b807
Deleted: sha256:a617bd7a310b090a2009887c88f91f1cd0e3c62024f05de9d080974da8cd303f
Deleted: sha256:3764e41990df0e1d74002f6e5c9216b3db80cef7cca581b215ec8d976762b0eb
Deleted: sha256:20724bef2f46162aab34c318c5de84580d2b010244d53228e5cb18b3ee545fd1
Deleted: sha256:f163978d2447e776307caaba226b83d07c8af497d9b3e59778ba6ddb663a7e8d
Deleted: sha256:187107f7c00ed031ec24864d2c3166b8b88cfa237ca2cc93bef921327b8332b9
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu latest c9d990395902 4 days ago 113 MB
docker.io/centos latest e934aafc2206 10 days ago 199 MB
www.docker.com/tryit/
docker search tutorial
docker pull learn/tutorial
docker pull learn/tutorial echo "hello world"
docker pull learn/tutorial apt-get install -y ping 容器中安装ping命令
docker ps -l 查看有哪些容器
docker commit 6982a9948422 learn/ping 容器提交 相当于创建了一个新的镜像 会返回一个新的镜像id
docker run learn/ping ping www.google.com
docker ps 查看当前运行的容器
docker inspect 容器ID : 详细信息
docker images 查看有哪些镜像
docker push learn/ping保存到docker hub上