简体   繁体   English

从Debian运行Docker容器:拉伸图像不起作用

[英]Running docker container from debian:stretch image does not work

I am trying to run a container based on the debian:stretch image, but this does not work: 我正在尝试基于debian:stretch图像运行容器,但这不起作用:

docker container run --detach debian:stretch

outputs: 输出:

7976eb7074289a741a2b183634345fc8519359cba4d543c03b0a6d4e5d7e0d53

And

docker ps -a

outputs: 输出:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
7976eb707428        debian:stretch      "bash"              3 seconds ago       Exited (0) 2 seconds ago                       vigorous_lumiere

Whereas it works well with the latest nginx image: 而与最新的nginx图像配合使用则效果很好:

docker run --detach nginx:latest

53ed18b5d1a7c72aa92bab0ca679269514db79f31a1d3759c2e25c7fdb1e82ff 53ed18b5d1a7c72aa92bab0ca679269514db79f31a1d3759c2e25c7fdb1e82ff

docker ps -a

outputs: 输出:

CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                          PORTS               NAMES
53ed18b5d1a7        nginx:latest        "nginx -g 'daemon of…"   2 seconds ago        Up 2 seconds                    80/tcp              admiring_hawking
7976eb707428        debian:stretch      "bash"                   About a minute ago   Exited (0) About a minute ago                       vigorous_lumiere

Why does the container based on the debian:stretch image that I am instantiating does not work? 为什么基于我实例化的debian:stretch映像的容器不起作用? Does this come from the debian image? 这是否来自debian映像?

I am running Docker version 18.09.1, build 4c52b90 on Ubuntu 16.04 LTS 我正在运行Docker版本18.09.1,在Ubuntu 16.04 LTS上构建4c52b90

Your container literally doesn't do anything: it starts a shell, but since it's running as a background process and doesn't have anything on its stdin, it immediately exits. 您的容器实际上不执行任何操作:它启动外壳程序,但是由于它作为后台进程运行,并且在stdin上没有任何内容,因此它立即退出。

You should read the official Docker tutorial on building and running custom images . 您应该阅读有关构建和运行自定义映像的官方Docker教程。 Generally you should work by building your application into a custom image, setting up that image's default CMD to run your application, and using docker build and docker run (or a tool like Docker Compose) to run the assembly. 通常,您应该通过以下步骤进行工作:将应用程序构建到自定义映像中,设置该映像的默认CMD以运行您的应用程序,并使用docker builddocker run (或类似Docker Compose的工具)运行程序集。 There's not much point in running a plain Linux distribution container. 运行普通的Linux分发容器没有什么意义。

(Also remember that it's extremely routine to docker rm containers, and so anything you do in an interactive shell in a container is very likely to get lost.) (还请记住,对于docker rm容器来说,这是极为常规的操作,因此,在容器中的交互式shell中执行的任何操作很可能会丢失。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM