Docker新手,这张图片是否成功创建?

时间:2016-06-29 19:57:31

标签: 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 

这是我的Dockerfile:

FROM ubuntu:14.04.3
RUN sudo apt-get install git

docker图片返回:

ubuntu              14.04.3             3876b81b5a81        5 months ago        187.9 MB

图像是新创建的,但是出现在'5个月前',如果这不是指示今天创建的那么?

因为已经安装了git然后导致此错误? :

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

2 个答案:

答案 0 :(得分:1)

  1. 默认情况下,如果APT即将安装一堆总大小超过某个值的软件包,它会在安装前要求您确认。但是,构建Docker镜像时运行的命令都是非交互式的,因此apt-get install git将无法得到问题的答案,因此它将在不执行任何操作的情况下退出。您需要在Dockerfile中使用apt-get install -y git才能说出&#34; yes&#34;自动提示。 (注意sudo在这里是多余的,因为该命令已经以root身份运行。)

  2. 由于您的Dockerfile在第一条指令上失败,docker build实际上并没有创建新图像。 docker images的输出显示您只有一张图片ubuntu:14.04.3,以及五个月前创建的图片。

  3. Git尚未安装,&#34;因为它没有出现在官方ubuntu Docker图像中。是否在主机系统上安装了Git,对于它是否已安装在Docker镜像中绝对没有影响。

答案 1 :(得分:1)

使用apt-get install git -y重试git安装(如果需要,请使用sudo)。这应该有用。