Docker新手,这个图像是否成功创建? [英] Docker newbie, is this image created successfully ?

查看:252
本文介绍了Docker新手,这个图像是否成功创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行 docker build。输出:

Sending build context to Docker daemon 2.048 kB
Step 1 : FROM ubuntu:14.04.3
14.04.3: Pulling from library/ubuntu
8387d9ff0016: Pull complete 
3b52deaaf0ed: Pull complete 
4bd501fad6de: Pull complete 
a3ed95caeb02: Pull complete 
Digest: sha256:2febbcede4f3eb82ae0dc44518a2e2a7b06a0452685e64e6b13f51b278294780
Status: Downloaded newer image for ubuntu:14.04.3
 ---> 3876b81b5a81
Step 2 : RUN sudo apt-get install git
 ---> Running in cda85e00be34
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  ca-certificates git-man krb5-locales libasn1-8-heimdal libcurl3-gnutls
  libedit2 liberror-perl libgssapi-krb5-2 libgssapi3-heimdal
  libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal
  libhx509-5-heimdal libidn11 libk5crypto3 libkeyutils1 libkrb5-26-heimdal
  libkrb5-3 libkrb5support0 libldap-2.4-2 libroken18-heimdal librtmp0
  libsasl2-2 libsasl2-modules libsasl2-modules-db libwind0-heimdal libx11-6
  libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxmuu1 openssh-client
  openssl patch rsync xauth
Suggested packages:
  gettext-base git-daemon-run git-daemon-sysvinit git-doc git-el git-email
  git-gui gitk gitweb git-arch git-bzr git-cvs git-mediawiki git-svn krb5-doc
  krb5-user libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql
  libsasl2-modules-gssapi-mit libsasl2-modules-gssapi-heimdal ssh-askpass
  libpam-ssh keychain monkeysphere ed diffutils-doc openssh-server
Recommended packages:
  ssh-client
The following NEW packages will be installed:
  ca-certificates git git-man krb5-locales libasn1-8-heimdal libcurl3-gnutls
  libedit2 liberror-perl libgssapi-krb5-2 libgssapi3-heimdal
  libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal
  libhx509-5-heimdal libidn11 libk5crypto3 libkeyutils1 libkrb5-26-heimdal
  libkrb5-3 libkrb5support0 libldap-2.4-2 libroken18-heimdal librtmp0
  libsasl2-2 libsasl2-modules libsasl2-modules-db libwind0-heimdal libx11-6
  libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxmuu1 openssh-client
  openssl patch rsync xauth
0 upgraded, 39 newly installed, 0 to remove and 0 not upgraded.
Need to get 7671 kB of archives.
After this operation, 41.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The command '/bin/sh -c sudo apt-get install git' returned a non-zero code: 1

ssh user@ .com
MACLA910275:~ user$ ssh user@ .com

Unauthorized access to or use of this system is prohibited.
All access and use may be monitored and recorded.

user@ .com's password: 
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-39-generic x86_64)

Unauthorized access to or use of this system is prohibited. All access and use may be monitored and recorded.
Unauthorized access to or use of this system is prohibited. All access and use may be monitored and recorded.
user@ :~$ ls
user@ :~$ pwd
/home/user
user@ :~$ sudo apt-get install git
Reading package lists... Done
Building dependency tree       
Reading state information... Done
git is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 66 not upgraded.
user@ :~$ docker
Usage: docker [OPTIONS] COMMAND [arg...]
       docker daemon [ --help | ... ]
       docker [ --help | -v | --version ]

A self-sufficient runtime for containers.

Options:

  --config=~/.docker              Location of client config files
  -D, --debug                     Enable debug mode
  -H, --host=[]                   Daemon socket(s) to connect to
  -h, --help                      Print usage
  -l, --log-level=info            Set the logging level
  --tls                           Use TLS; implied by --tlsverify
  --tlscacert=~/.docker/ca.pem    Trust certs signed only by this CA
  --tlscert=~/.docker/cert.pem    Path to TLS certificate file
  --tlskey=~/.docker/key.pem      Path to TLS key file
  --tlsverify                     Use TLS and verify the remote
  -v, --version                   Print version information and quit

Commands:
    attach    Attach to a running container
    build     Build an image from a Dockerfile
    commit    Create a new image from a container's changes
    cp        Copy files/folders between a container and the local filesystem
    create    Create a new container
    diff      Inspect changes on a container's filesystem
    events    Get real time events from the server
    exec      Run a command in a running container
    export    Export a container's filesystem as a tar archive
    history   Show the history of an image
    images    List images
    import    Import the contents from a tarball to create a filesystem image
    info      Display system-wide information
    inspect   Return low-level information on a container or image
    kill      Kill a running container
    load      Load an image from a tar archive or STDIN
    login     Log in to a Docker registry
    logout    Log out from a Docker registry
    logs      Fetch the logs of a container
    network   Manage Docker networks
    pause     Pause all processes within a container
    port      List port mappings or a specific mapping for the CONTAINER
    ps        List containers
    pull      Pull an image or a repository from a registry
    push      Push an image or a repository to a registry
    rename    Rename a container
    restart   Restart a container
    rm        Remove one or more containers
    rmi       Remove one or more images
    run       Run a command in a new container
    save      Save one or more images to a tar archive
    search    Search the Docker Hub for images
    start     Start one or more stopped containers
    stats     Display a live stream of container(s) resource usage statistics
    stop      Stop a running container
    tag       Tag an image into a repository
    top       Display the running processes of a container
    unpause   Unpause all processes within a container
    update    Update configuration of one or more containers
    version   Show the Docker version information
    volume    Manage Docker volumes
    wait      Block until a container stops, then print its exit code

Run 'docker COMMAND --help' for more information on a command.
user@ :~$ sudo apt-get install g
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package g
user@ :~$ 
user@ :~$ 
user@ :~$ 
user@ :~$ 
user@ :~$ 
user@ :~$ docker images
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
user@ :~$ docker version
Client:
 Version:      1.11.2
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   b9f10c9
 Built:        Wed Jun  1 21:47:50 2016
 OS/Arch:      linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
user@ :~$ sudo -i
root@ :~# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              693bce725149        3 weeks ago         967 B
root@ :~# \
> 
root@ :~# 
root@ :~# 
root@ :~# 
root@ :~# 
root@ :~# 
root@ :~# DOCKER PS -a
DOCKER: command not found
root@ :~# docker ps -1
flag provided but not defined: -1
See 'docker ps --help'.
root@ :~# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                  PORTS               NAMES
4e22edd9df8a        hello-world         "/hello"            2 days ago          Exited (0) 2 days ago                       big_boyd
root@ :~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.3 LTS
Release:    14.04
Codename:   trusty
root@ :~# pwd
/root
root@ :~# mkdir docker-myproject
root@ :~# cd docker-myproject/
root@ :~/docker-myproject# ls
root@ :~/docker-myproject# vi Dockerfile
root@ :~/docker-myproject# vi Dockerfile
root@ :~/docker-myproject# vi Dockerfile
root@ :~/docker-myproject# vi Dockerfile
root@ :~/docker-myproject# vi Dockerfile
root@ :~/docker-myproject# vi Dockerfile
root@ :~/docker-myproject# 
root@ :~/docker-myproject# 
root@ :~/docker-myproject# docker build .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM ubuntu 14.04.3
Error parsing reference: "ubuntu 14.04.3" is not a valid repository/tag
root@ :~/docker-myproject# vi Dockerfile
root@ :~/docker-myproject# 
root@ :~/docker-myproject# 
root@ :~/docker-myproject# docker build .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM ubuntu:14.04.3
14.04.3: Pulling from library/ubuntu
8387d9ff0016: Pull complete 
3b52deaaf0ed: Pull complete 
4bd501fad6de: Pull complete 
a3ed95caeb02: Pull complete 
Digest: sha256:2febbcede4f3eb82ae0dc44518a2e2a7b06a0452685e64e6b13f51b278294780
Status: Downloaded newer image for ubuntu:14.04.3
 ---> 3876b81b5a81
Step 2 : RUN sudo apt-get install git
 ---> Running in cda85e00be34
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  ca-certificates git-man krb5-locales libasn1-8-heimdal libcurl3-gnutls
  libedit2 liberror-perl libgssapi-krb5-2 libgssapi3-heimdal
  libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal
  libhx509-5-heimdal libidn11 libk5crypto3 libkeyutils1 libkrb5-26-heimdal
  libkrb5-3 libkrb5support0 libldap-2.4-2 libroken18-heimdal librtmp0
  libsasl2-2 libsasl2-modules libsasl2-modules-db libwind0-heimdal libx11-6
  libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxmuu1 openssh-client
  openssl patch rsync xauth
Suggested packages:
  gettext-base git-daemon-run git-daemon-sysvinit git-doc git-el git-email
  git-gui gitk gitweb git-arch git-bzr git-cvs git-mediawiki git-svn krb5-doc
  krb5-user libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql
  libsasl2-modules-gssapi-mit libsasl2-modules-gssapi-heimdal ssh-askpass
  libpam-ssh keychain monkeysphere ed diffutils-doc openssh-server
Recommended packages:
  ssh-client
The following NEW packages will be installed:
  ca-certificates git git-man krb5-locales libasn1-8-heimdal libcurl3-gnutls
  libedit2 liberror-perl libgssapi-krb5-2 libgssapi3-heimdal
  libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal
  libhx509-5-heimdal libidn11 libk5crypto3 libkeyutils1 libkrb5-26-heimdal
  libkrb5-3 libkrb5support0 libldap-2.4-2 libroken18-heimdal librtmp0
  libsasl2-2 libsasl2-modules libsasl2-modules-db libwind0-heimdal libx11-6
  libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxmuu1 openssh-client
  openssl patch rsync xauth
0 upgraded, 39 newly installed, 0 to remove and 0 not upgraded.
Need to get 7671 kB of archives.
After this operation, 41.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The command '/bin/sh -c sudo apt-get install git' returned a non-zero code: 1
root@ :~/docker-myproject# docker build .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM ubuntu:14.04.3
 ---> 3876b81b5a81
Step 2 : RUN sudo apt-get install git
 ---> Running in 1de93513f856
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  ca-certificates git-man krb5-locales libasn1-8-heimdal libcurl3-gnutls
  libedit2 liberror-perl libgssapi-krb5-2 libgssapi3-heimdal
  libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal
  libhx509-5-heimdal libidn11 libk5crypto3 libkeyutils1 libkrb5-26-heimdal
  libkrb5-3 libkrb5support0 libldap-2.4-2 libroken18-heimdal librtmp0
  libsasl2-2 libsasl2-modules libsasl2-modules-db libwind0-heimdal libx11-6
  libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxmuu1 openssh-client
  openssl patch rsync xauth
Suggested packages:
  gettext-base git-daemon-run git-daemon-sysvinit git-doc git-el git-email
  git-gui gitk gitweb git-arch git-bzr git-cvs git-mediawiki git-svn krb5-doc
  krb5-user libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql
  libsasl2-modules-gssapi-mit libsasl2-modules-gssapi-heimdal ssh-askpass
  libpam-ssh keychain monkeysphere ed diffutils-doc openssh-server
Recommended packages:
  ssh-client
The following NEW packages will be installed:
  ca-certificates git git-man krb5-locales libasn1-8-heimdal libcurl3-gnutls
  libedit2 liberror-perl libgssapi-krb5-2 libgssapi3-heimdal
  libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal
  libhx509-5-heimdal libidn11 libk5crypto3 libkeyutils1 libkrb5-26-heimdal
  libkrb5-3 libkrb5support0 libldap-2.4-2 libroken18-heimdal librtmp0
  libsasl2-2 libsasl2-modules libsasl2-modules-db libwind0-heimdal libx11-6
  libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxmuu1 openssh-client
  openssl patch rsync xauth
0 upgraded, 39 newly installed, 0 to remove and 0 not upgraded.
Need to get 7671 kB of archives.
After this operation, 41.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The command '/bin/sh -c sudo apt-get install git' returned a non-zero code: 1
root@ :~/docker-myproject# git
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty Git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

'git help -a' and 'git help -g' lists available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
root@ :~/docker-myproject# ls
Dockerfile
root@ :~/docker-myproject# vi Dockerfile 

这是我的Docker文件:

Here is my Dockerfile :

FROM ubuntu:14.04.3
RUN sudo apt-get install git

docker图像返回:

docker images returns :

ubuntu              14.04.3             3876b81b5a81        5 months ago        187.9 MB

图像是新创建的,但是在5个月前被显示为被创建,如果这不是今天创建的?

The image is newly created but is appearing as being created '5 months ago' should this not be indicating is created today ?

由于git已经被那么安装正在造成这个错误? :

As git has already been installed is then is causing this error ? :

After this operation, 41.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
The command '/bin/sh -c sudo apt-get install git' returned a non-zero code: 1


推荐答案


  1. 默认情况下,如果APT要安装一堆总大小超过某个值的包,您在安装前进行确认。然而,在构建Docker映像时运行的命令都是非交互式的,因此 apt-get install git 将无法得到其问题的答案,所以它会退出而不做任何事情。您需要在Docker文件中使用 apt-get install -y git ,以便自动对提示说是。 (请注意,这里的$ code> sudo 是多余的,因为命令已经以root身份运行。)

  1. By default, if APT is about to install a bunch of packages whose total size exceeds some value, it will ask you for confirmation before installing. However, the commands run when building a Docker image are all non-interactive, and so apt-get install git will not be able to get an answer to its question, and so it will exit without doing anything. You need to use apt-get install -y git in your Dockerfile in order to say "yes" to the prompt automatically. (Note that sudo is superfluous here, as the command is already running as root.)

您的Dockerfile在第一条指令失败, docker build 实际上并没有创建新的映像。 docker图像的输出显示您只有一个图像, ubuntu:14.04.3 ,就是那个图像这是在五个月前创建的。

As your Dockerfile failed on the first instruction, docker build did not actually create a new image. The output from docker images shows you that you have only one image, ubuntu:14.04.3, and it's that image that was created five months ago.

Git尚未已经安装,因为它不存在于官方的 ubuntu Docker图像。 Git是否安装在您的主机系统上,绝对不管是否安装在Docker镜像中。

Git has not "already been installed," as it is not present in the official ubuntu Docker images. Whether Git is installed on your host system has absolutely no bearing on whether it's installed in your Docker images.

这篇关于Docker新手,这个图像是否成功创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆