温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么运行docker容器

发布时间:2021-12-13 11:24:02 来源:亿速云 阅读:147 作者:iii 栏目:大数据

本篇内容介绍了“怎么运行docker容器”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

 首先我们查看下当前本地docker镜像:

[root@xinsz10 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

可以看到当前是没有任何镜像的,然后我们执行第二条命令,来拉取一个hello-world镜像

[root@xinsz10 ~]# docker pull hello-world
Using default tag: latest   

#相当于给我们的helloworld后面加 了一个:latest
latest: Pulling from library/hello-world  

#正在拉取library下的一个hello-world
Digest: sha256:b2ba691d8aac9e5ac3644c0788e3d3823f9e97f757f01d2ddc6eb5458df9d801
Status: Image is up to date for hello-world:latest

查看是否下载完成  也就是查看本地镜像

[root@xinsz10 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              05a3bd381fc2        4 weeks ago         1.84kB

注:  REPOSITORY 是镜像名

       IMAGE ID 是64位的字符串,这里自动被截掉了,只显示了16位,可以唯一标识我们的镜像

       CREATED   修改时间

        SIZE    大小

镜像的名字在网站上都可以查到,docker 提供了一个镜像仓库,hub.docker.com    默认到这里下载

镜像下载完成后,我们来看看如何运行

具体命令:  docker  run  +选项  IMAGE [:TAG] [命令] [ARG..]
[root@xinsz10 ~]# docker run hello-world
WARNING: IPv4 forwarding is disabled. Networking will not work.

Hello from Docker!
This message shows that your installation appears to be working correctly.  #如果这个消息显示出来说明你的安装已经OK了

下面这些英文,是在告诉我们docker运行时经过了那几个步骤
To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/
根据上面弹出的英文提示,(关于docker执行docker run时所做的那些操作)
我们用示意图来看看docker pull和docker run的整个流程:

怎么运行docker容器

左边两个是在本机运行的,   最右面是远程镜像

docker pull会检查本机images里镜像是否存在,如果存在且版本正确,就直接用,如果不存在就从docker 仓库下载回来使用.

docker run也是一样,当执行这个命令时候,也需要到本地的images检查是否存在,不存在也会跟docker pull一样到远端去拉取镜像.

“怎么运行docker容器”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI