简体   繁体   中英

Start container by image ID

According to the Docker manual, the command for staring a container is 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?

UPDATE:

There is a Dockerfile which contains

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. , I see the steps for pulling the image and apt commands. But it terminates with this error about not finding 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.

$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Docker images and containers are different things. 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

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 :

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

UPDATE:

The docker build command is used to create an image NOT a container. 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.

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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