docker 镜像简单使用

使用docker之前我们需要先了解docker三大核心概念:镜像、容器、仓库

本章主要介绍 docker镜像 的使用,概念网上太多。

查看镜像信息

在安装了docker服务后,我们启动测试docker 运行了hello-world,本地保存了hello-world镜像

[root@hw-biz-alpha admin]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        7 months ago        1.84kB

获取镜像

docker pull NAME[:TAG]
通过TAG,我们可以指定拉取的镜像版本。
TAG的默认值 latest 。例如: docker pull ubuntu 实际是 docker pull ubuntu:latest

获取ubuntu镜像,没有指定TAG,默认获取最新版本

docker pull ubuntu

获取后,再次查看镜像信息,可以看到多了个 latest标签的ubuntu镜像

[root@hw-biz-alpha admin]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              3556258649b2        2 weeks ago         64.2MB
hello-world         latest              fce289e99eb9        7 months ago        1.84kB

获取指定TAG的ubuntu镜像,如 docker pull ubuntu:14.04 后 再次查看镜像信息

[root@hw-biz-alpha admin]# docker pull ubuntu:14.04
14.04: Pulling from library/ubuntu
a7344f52cb74: Pull complete 
515c9bb51536: Pull complete 
e1eabe0537eb: Pull complete 
4701f1215c13: Pull complete 
Digest: sha256:2f7c79927b346e436cc14c92bd4e5bd778c3bd7037f35bc639ac1589a7acfa90
Status: Downloaded newer image for ubuntu:14.04
docker.io/library/ubuntu:14.04
[root@hw-biz-alpha admin]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              3556258649b2        2 weeks ago         64.2MB
ubuntu              14.04               2c5e00d77a67        2 months ago        188MB
hello-world         latest              fce289e99eb9        7 months ago        1.84kB

运行镜像创建的容器

docker run
运行最新的ubuntu镜像(如过要运行指定版本的需要指定TAG,如ubuntu:14.04)

sudo docker run -t -i ubuntu /bin/bash

[root@hw-biz-alpha admin]# docker run -i -t ubuntu /bin/bash
root@3f82741ff5d8:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@3f82741ff5d8:/# exit
exit
[root@hw-biz-alpha admin]# 

参数
-i开启了input(输入)功能
-t开启了一个连接容器里边的terminal(终端)

-t -i 的意义,如果仅仅启动一个linux系统,没有交互终端,ubuntu镜像容器启动后立马就结束掉了(一个什么都没运行的不能交互的操作系统要来干嘛),有终端但没有输入操作还是什么都不能做!当然如果只是想静静的后台运行,那就不需要-t -i参数,比如我启动一个自己的服务器后台程序,只需要后台运行,那就不用参数-t -i,后台运行参数-d

这里的 /bin/bash 指启动容器后执行命令 /bin/bash
后面会介绍Dockerfile的CMD ["/bin/bash"] 也是指定容器启动后 执行 /bin/bash 命令,docker run 指定启动运行命令会覆盖Dockerfile的CMD

搜寻镜像

docker search TERM,例如:docker search ubuntu
参数:

automated=true 仅显示自动创建的
--no-trunc=true不截断输出信息就是字数过多用...代替的信息
-s,--starts=n输出n个星以上的镜像
[root@hw-biz-alpha admin]# docker search ubuntu
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
ubuntu                                                    Ubuntu is a Debian-based Linux operating sys…   9817                [OK]                
dorowu/ubuntu-desktop-lxde-vnc                            Docker image to provide HTML5 VNC interface …   331                                     [OK]
rastasheep/ubuntu-sshd                                    Dockerized SSH service, built on top of offi…   227                                     [OK]
consol/ubuntu-xfce-vnc                                    Ubuntu container with "headless" VNC session…   186                                     [OK]
ubuntu-upstart                                            Upstart is an event-based replacement for th…   99                  [OK]                
ansible/ubuntu14.04-ansible                               Ubuntu 14.04 LTS with ansible                   97                                      [OK]
neurodebian                                               NeuroDebian provides neuroscience research s…   58                  [OK]                
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          50                                      [OK]
ubuntu-debootstrap                                        debootstrap --variant=minbase --components=m…   40                  [OK]                
i386/ubuntu                                               Ubuntu is a Debian-based Linux operating sys…   18                                      
1and1internet/ubuntu-16-apache-php-5.6                    ubuntu-16-apache-php-5.6                        14                                      [OK]
ppc64le/ubuntu                                            Ubuntu is a Debian-based Linux operating sys…   13                                      
1and1internet/ubuntu-16-apache-php-7.0                    ubuntu-16-apache-php-7.0                        13                                      [OK]
eclipse/ubuntu_jdk8                                       Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, …   11                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10   ubuntu-16-nginx-php-phpmyadmin-mariadb-10       11                                      [OK]
1and1internet/ubuntu-16-nginx-php-5.6                     ubuntu-16-nginx-php-5.6                         8                                       [OK]
1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4         ubuntu-16-nginx-php-5.6-wordpress-4             7                                       [OK]
1and1internet/ubuntu-16-apache-php-7.1                    ubuntu-16-apache-php-7.1                        6                                       [OK]
darksheer/ubuntu                                          Base Ubuntu Image -- Updated hourly             5                                       [OK]
1and1internet/ubuntu-16-nginx-php-7.0                     ubuntu-16-nginx-php-7.0                         4                                       [OK]
pivotaldata/ubuntu                                        A quick freshening-up of the base Ubuntu doc…   2                                       
1and1internet/ubuntu-16-php-7.1                           ubuntu-16-php-7.1                               1                                       [OK]
smartentry/ubuntu                                         ubuntu with smartentry                          1                                       [OK]
1and1internet/ubuntu-16-sshd                              ubuntu-16-sshd                                  1                                       [OK]
pivotaldata/ubuntu-gpdb-dev                               Ubuntu images for GPDB development              0                                       

删除镜像

docker rmi REPOSITORY:TAGdocker rmi IMAGEID
删除某个指定版本镜像不会影响latest镜像

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值