首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >码头Ubuntu 12.04

码头Ubuntu 12.04
EN

Stack Overflow用户
提问于 2014-05-21 17:53:20
回答 1查看 3.8K关注 0票数 2

当我从Docker索引下载一个全新的Ubuntu:12.04容器时,它中的任何内容都不起作用。它甚至没有sudo或lsb_release。有没有人知道为什么或如何将容器送到一个可用的状态?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2014-05-22 08:13:25

看看你做了什么,知道你期望什么,会很有趣的。但以下是一个有用的例子,也许这会有所帮助:

代码语言:javascript
复制
# get the image
docker pull ubuntu

# run pwd in the image and see that you are in "/"
docker run ubuntu pwd
/

# curl a website and see that curl is not installed
docker run ubuntu curl www.google.com
2014/05/22 07:52:42 exec: "curl": executable file not found in $PATH

# update apt-get
docker run ubuntu apt-get update

# Now attention: Docker will not change the base image Ubuntu! 
# So apt is not updated in your Ubuntu image! Instead, Docker 
# will create a new container every time you run a command. Let's see 
# how the new container is called (your CONTAINER ID will be different!):
docker ps -a
CONTAINER ID        IMAGE                             COMMAND                CREATED             STATUS
a7ae5dae6dd8        ubuntu:12.04                      apt-get update         53 seconds ago      Exited (0) 40 seconds ago                                                     nostalgic_lumiere

# So container a7ae5dae6dd8 is Ubuntu + apt-get update. Give it
# a name and save it as a new image:
docker commit a7ae my-ubuntu

# Now install curl in my-ubuntu
docker run my-ubuntu apt-get install -y curl

# And again: the image my-ubuntu is not changed! Instead we have a new 
# container which has curl installed:
docker ps -a
CONTAINER ID        IMAGE                             COMMAND                CREATED              STATUS
e07118069479        my-ubuntu:latest                  apt-get install -y c   About a minute ago   Exited (0) 45 seconds ago                                                      naughty_wozniak
a7ae5dae6dd8        ubuntu:12.04                      apt-get update         9 minutes ago        Exited (0) 9 minutes ago                                                       nostalgic_lumiere

# Let's save this container as our image:
docker commit e071 my-ubuntu

# and now run curl on my-ubuntu:
docker run my-ubuntu curl www.google.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   258  100   258    0     0  10698      0 --:--:-- --:--:-- --:--:-- 25800
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.de/?gfe_rd=cr&amp;ei=ZrB9U4_eH4HW_AbjvoG4Ag">here</A>.
</BODY></HTML>

我希望这能帮助我们了解码头的工作原理。要使映像进入使用状态(安装软件包和其他东西),您当然不会像上面那样手工操作。相反,您可以创建一个Dockerfile来构建一个映像:

代码语言:javascript
复制
FROM Ubuntu
RUN apt-get update
RUN apt-get install -y curl

并构建您想要的图像,如docker build . -t my-ubuntu

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23790496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档