微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

三、Docker 基础用法

3.1 search images

# docker search Ubuntu    # 搜索镜像

3.2 pull images

# docker pull ubuntu   # 获取 ubuntu 官方镜像
# docker images         # 查看当前镜像列表

3.3 running an interactive shell

# docker run -i -t ubuntu:14.04 /bin/bash

docker run -启动一个docker容器
-t - 分配一个(伪)tty (link is external)
-i - 交互模式 (so we can interact with it)
ubuntu:14.04 - 使用 ubuntu 基础镜像 14.04
/bin/bash - 运行命令 bash shell
注: ubuntu 会有多个版本,通过指定tag来启动特定的版本 [image]:[tag]运行命令测试
[root@Boxiaoyuan ~]# docker run -it centos:6 /bin/bash
[root@fa0101ec9408 /]# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:AC:11:00:04  
          inet addr:172.17.0.4  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:4/64 Scope:Link
          UP broADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:238 (238.0 b)  TX bytes:418 (418.0 b)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@fa0101ec9408 /]# cat /etc/centos-release 
CentOS release 6.10 (Final)
[root@fa0101ec9408 /]# exit
exit
[root@Boxiaoyuan ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                          PORTS               NAMES
fa0101ec9408        centos:6            "/bin/bash"         36 seconds ago      Exited (0) 5 seconds ago                            adoring_mestorf     
635a6d6ecc18        centos:6            "/bin/bash"         3 minutes ago       Exited (0) About a minute ago                       reverent_einstein   
bcd12a83d56a        ubuntu:14.04        "/bin/bash"         11 minutes ago      Exited (0) 8 minutes ago                            evil_meitner        
3ea8b1a018bc        hello-world         "/hello"            51 minutes ago      Exited (0) 51 minutes ago                           drunk_lumiere       
[root@Boxiaoyuan ~]# docker start fa0101ec9408
fa0101ec9408
[root@Boxiaoyuan ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                      PORTS               NAMES
fa0101ec9408        centos:6            "/bin/bash"         About a minute ago   Up 11 seconds                                   adoring_mestorf     
635a6d6ecc18        centos:6            "/bin/bash"         4 minutes ago        Exited (0) 2 minutes ago                        reverent_einstein   
bcd12a83d56a        ubuntu:14.04        "/bin/bash"         12 minutes ago       Exited (0) 9 minutes ago                        evil_meitner        
3ea8b1a018bc        hello-world         "/hello"            52 minutes ago       Exited (0) 52 minutes ago                       drunk_lumiere       
[root@Boxiaoyuan ~]# docker stop fa0101ec9408
fa0101ec9408

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐