Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

How to debug a docker container that cannot be listed and will not run?

I am attempting to run the OpenDXL publish/subscribe broker according to these instructions. Docker is installed on Ubuntu 18.04.5 LTS

Running the container apparently does nothing: it returns a container ID and displays no error messages. It is supposed to create files in the specified directory but does not.

$ sudo docker container ls
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
$ sudo docker run -d --name opendxl-broker -p 8443:8443 -p 8883:8883 -v /home/user/opendxl/opendxl-broker:/dxlbroker-volume opendxl/opendxl-broker
1b237a1c42a4813fb5f9144a1df7255108478e3ad9b08aa754abb18bb33c89ba
$

Docker shows no container with that ID:

$ sudo docker container ls
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
$

Attempting to run it again fails:

$ sudo docker run -d --name opendxl-broker -p 8443:8443 -p 8883:8883
-v /home/user/opendxl/opendxl-broker:/dxlbroker-volume opendxl/opendxl-broker
docker: Error response from daemon: Conflict. The container name "/opendxl-broker" is already in use by container "1b237a1c42a4813fb5f9144a1df7255108478e3ad9b08aa754abb18bb33c89ba". You have to remove (or rename) that container to be able to reuse that name. See 'docker run --help'.
$ sudo docker ps
CONTAINER ID   IMAGE   COMMAND   CREATED   STATUS    PORTS     NAMES
$

Prune gets rid of stopped containers:

$ sudo docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
1b237a1c42a4813fb5f9144a1df7255108478e3ad9b08aa754abb18bb33c89ba

Total reclaimed space: 181B
$

Questions:

  1. how do you list all containers, stopped and running? I'd assume that docker container ls List containers is supposed to list all containers, while docker ps shows running processes. What kind of zombie state is my container in that it cannot be listed but it exists and can be removed by prune?

  2. How do you debug why a container returns an ID, generates no errors, but won't run?

FYI:

$ sudo docker version
Client: Docker Engine - Community
 Version:           20.10.2
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        2291f61
 Built:             Mon Dec 28 16:17:32 2020
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.2
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8891c58
  Built:            Mon Dec 28 16:15:09 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
question from:https://stackoverflow.com/questions/65943309/how-to-debug-a-docker-container-that-cannot-be-listed-and-will-not-run

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For listing all containers running/stopped you should run:

docker ps -a
docker ps -aq // this command is for piping the list into anther command without header

you run the container with detached command with -d flag so it does not show the error or std in/out of the application running in the container. you have to run it with undetached mode to see what happens inside

sudo docker run  --name opendxl-broker -p 8443:8443 -p 8883:8883 -v /home/user/opendxl/opendxl-broker:/dxlbroker-volume opendxl/opendxl-broker

you can also run it with -it flag in interactive mode.

You can run the docker logs [ContainerName] or docker logs [ContainerID] command even on stopped containers to see the logs


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...