如何重启我的Docker容器?

时间:2018-03-26 08:45:47

标签: docker

ps -a给我们的是

              NAMES
4514ea1b7b22        debian                                     "--name gallant_spen…"   9 minutes ago       Created                                                  peaceful_engelbart
df9bd2731a2b        debian                                     "--name gallant_spen…"   9 minutes ago       Created                                                  happy_hodgkin
dd5b1f1b39ec        redis                                      "docker-entrypoint.s…"   32 minutes ago      Up 31 minutes                 6379/tcp                   myred
ffd6ef9d8bd5        redis                                      "docker-entrypoint.s…"   32 minutes ago      Exited (127) 32 minutes ago                              festive_jennings
9d01d321adad        redis                                      "docker-entrypoint.s…"   33 minutes ago      Exited (0) 32 minutes ago                                agitated_shannon
eb7c13e7cdee        debian                                     "ls /data"               2 days ago          Exited (0) 9 seconds ago                                 gallant_spence
8991a31b1e38        debian                                     "ls /data"               2 days ago          Exited (0) 2 days ago                                    determined_minsky

我试过这种方式

docker start  `docker ps -q -l` gallant_spence

但错误发生了

Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"--name\": executable file not found in $PATH": unknown
gallant_spence
Error: failed to start containers: 4514ea1b7b22

我对以前在此容器中的工作中已安装的数据量感兴趣

 "Mounts": [
        {
            "Type": "bind",
            "Source": "/home/mm/code/lesson_04",
            "Destination": "/data",
            "Mode": "",
            "RW": true,
            "Propagation": "rprivate"
        }
    ],

如果我尝试

mm@6830s:~$ docker start -ai gallant_spence 
one_sample.py
parallel_series.py

Python文件被添加到数据文件夹中,所以我认为它有效。然后我再试一次 docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
dd5b1f1b39ec        redis               "docker-entrypoint.s…"   About an hour ago   Up About an hour    6379/tcp            myred

热门解决这个问题?

1 个答案:

答案 0 :(得分:2)

start已停止的容器

docker start [OPTIONS] CONTAINER [CONTAINER...]

对于您的情况,您可以使用:

  • docker start gallant_spence
  • docker start eb7c13e7cdee

正如docker ps -a结果所示,您的容器配置了CMD

"ls /data"

这意味着每次start您的容器时,此命令都会运行,然后容器将退出。这就是容器的工作方式。当他们的主要流程完成后,他们退出。

关于您获得的错误以及docker ps -q -l

  • -q(来自“quiet”)告诉命令只打印容器ID
  • -l(来自“last”)告诉命令打印最新创建的容器

这意味着上面的命令会将您带回:4514ea1b7b22。如果我们把所有东西放在一起......

你的命令:

docker start  `docker ps -q -l` gallant_spence

转向:

docker start 4514ea1b7b22 gallant_spence

您收到的失败邮件是4514ea1b7b22,因为它没有正确设置CMD来启动。我看到类似的内容:--name gallant_spen…