【问题标题】:Running docker image does not work运行 docker 镜像不起作用
【发布时间】:2014-05-21 16:14:35
【问题描述】:

我是 Docker 新手,我正在为 Docker 做 Node.js 教程。我被困在这一步:http://docs.docker.io/en/latest/examples/nodejs_web_app/#building-your-image

我已经执行了这个:

$ docker build -t user/centos-node-hello .
...
Successfully built c04aea889b03

它构建成功。

$ docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
user/centos-node-hello   latest              c04aea889b03        23 minutes ago      667.9 MB
ubuntu                      13.10               9f676bd305a4        9 weeks ago         178 MB
ubuntu                      saucy               9f676bd305a4        9 weeks ago         178 MB
ubuntu                      raring              eb601b8965b8        9 weeks ago         166.5 MB
ubuntu                      13.04               eb601b8965b8        9 weeks ago         166.5 MB
ubuntu                      12.10               5ac751e8d623        9 weeks ago         161 MB
ubuntu                      quantal             5ac751e8d623        9 weeks ago         161 MB
ubuntu                      10.04               9cc9ea5ea540        9 weeks ago         180.8 MB
ubuntu                      lucid               9cc9ea5ea540        9 weeks ago         180.8 MB
ubuntu                      12.04               9cd978db300e        9 weeks ago         204.4 MB
ubuntu                      latest              9cd978db300e        9 weeks ago         204.4 MB
ubuntu                      precise             9cd978db300e        9 weeks ago         204.4 MB
busybox                     latest              769b9341d937        9 weeks ago         2.489 MB
centos                      6.4                 539c0211cd76        12 months ago       300.6 MB

现在我尝试运行图像:

$ docker run -p 49160:8080 -d user/centos-node-hello
995bfeef4edd723027480fdb43f097e2ba6a97b8fb1d2e9ec679dc1247f68a84

但是如果我检查进程,实例没有运行。

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS             PORTS  

有什么想法吗?谢谢。

【问题讨论】:

  • 尝试使用docker ps -l 打印最后运行的容器。您可以从该输出中获取容器 ID,并使用 docker logs <containerID> 查看日志以了解问题所在。
  • 检查docker version 看看你的守护进程和客户端是否是相同的版本。如果没有,请更新并重试。并非所有客户端/守护程序对都提供了良好的信息(在 Docker-1.0 之前的世界中,1.0 之后应该更稳定)。

标签: node.js macos centos docker


【解决方案1】:

试试:docker run -p 49160:8080 -i -t /centos-node-hello /bin/bash

有关选项的更多信息:http://docs.docker.com/reference/run/

【讨论】:

    【解决方案2】:

    不完全了解您的执行环境。我已经使用 Vagrant 成功运行了 docker-node-hello 示例。请参阅以下步骤。

    注意:由于 Docker Hub 上不再提供 centos:6.4 映像,我已将基础映像修改为 centos:6.6

    第 1 步:编辑Vagrantfile

    Vagrant.configure(2) do |config|
      config.vm.box = "williamyeh/ubuntu-trusty64-docker"
    
      config.vm.provision "shell", inline: <<-SHELL
        git clone https://github.com/enokd/docker-node-hello.git
        cd docker-node-hello
        sed -i -e 's/centos:6.4/centos:6.6/' Dockerfile
        docker build -t centos-node-hello .
        docker run -p 49160:8080 -d centos-node-hello
        docker ps
      SHELL
    end
    

    第二步:运行vagrant up

    第 3 步:运行 vagrant ssh -c "docker ps" 以查看容器是否处于活动状态。

    第 4 步:运行 vagrant ssh -c "curl localhost:49160" 以查看 index.js 是否运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-24
      • 2022-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-24
      相关资源
      最近更新 更多