简体   繁体   English

通过镜像 ID 启动容器

[英]Start container by image ID

According to the Docker manual, the command for staring a container is docker start [container_name] .根据 Docker 手册,启动容器的命令是docker start [container_name] However, the name is not mentioned in the following commands.但是,以下命令中未提及该名称。

$ docker images
REPOSITORY            TAG                        IMAGE ID       CREATED         SIZE
nvcr.io/nvidia/cuda   11.6.0-devel-ubuntu20.04   44b919ab35af   3 weeks ago     5.09GB
nvcr.io/nvidia/cuda   latest                     539690cdfcd6   15 months ago   4.77GB
$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

How can I start with tag or image ID?如何从标签或图像 ID 开始?

UPDATE:更新:

There is a Dockerfile which contains有一个 Dockerfile 其中包含

FROM nvcr.io/nvidia/cuda:11.6.0-devel-ubuntu20.04
RUN apt-get update
WORKDIR /opt
RUN apt-get update
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    build-essential \
    git \
    python \
    python-pip

When I run docker build.当我运行docker build. , I see the steps for pulling the image and apt commands. ,我看到了拉取图像和 apt 命令的步骤。 But it terminates with this error about not finding python-pip.但它因找不到 python-pip 的错误而终止。

...
Building dependency tree...
Reading state information...
Package python-pip is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  python3-pip

E: Package 'python-pip' has no installation candidate
The command '/bin/sh -c apt-get update && apt-get install -y --no-install-recommends     ca-certificates     build-essential     git     python     python-pip' returned a non-zero code: 100

The error is not a problem itself.错误本身不是问题。 I want to ssh to the container to see the folders inside /opt, but as docker ps shows, there is no container.我想ssh到容器里看看/opt里面的文件夹,但是docker ps显示,没有容器。

$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Docker images and containers are different things. Docker 镜像和容器是不同的东西。 You first need to create the container from the image.您首先需要从图像创建容器。

docker create [OPTIONS] IMAGE [COMMAND] [ARG...]

Containers that are stopped do not show up in docker ps unless you specify the -a flag:停止的容器不会显示在 docker ps中,除非您指定-a标志:

docker ps -a

Then you can start the created container然后就可以启动创建好的容器了

docker start CONTAINER

If you want you can perform create and start in a single step using run :如果需要,您可以使用run一步执行创建和启动:

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

UPDATE:更新:

The docker build command is used to create an image NOT a container. docker 构建命令用于创建图像而不是容器。 When the image is created you would then need to run it to create the container.创建映像后,您需要运行它来创建容器。

It looks like your image is not building properly though.看起来您的图像构建不正确。 Try replacing python and python-pip with python3 and python3-pip and rebuild.尝试用python3python3-pip替换pythonpython-pip pip 并重建。

I would also suggest tagging the image in order to more easily find it later:我还建议标记图像以便以后更容易找到它:

docker build -t my-image:latest .

When the image is properly created find it (or just use the tag if you tagged it) and run it.正确创建图像后,找到它(或者如果您标记了它,则只使用标签)并运行它。

If you tagged the image and you just want a shell inside the container then run it with如果您标记了图像并且您只想在容器内使用 shell 然后运行它

docker run -it my-image:latest /bin/bash

The -it options makes the shell interactable, my-image:latest is the image you want to create a container from and finally /bin/bash is the command you will execute in the newly created container (in this case it will give you a shell). -it选项使 shell 可交互, my-image:latest是您要从中创建容器的图像,最后/bin/bash是您将在新创建的容器中执行的命令(在这种情况下,它将为您提供一个壳)。

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

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