docker ps shows instances, but when I try to log in to the instance, it says it's not running?
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eaa62ff2df11 monitor_kibana "/usr/local/bin/dumb…" 4 months ago Up 9 days kibana
613dc901f2e1 monitor_elasticsearch-search "/usr/local/bin/dock…" 4 months ago Up 9 days elasticsearch-search
$ docker exec -it eaa62 bash
Error response from daemon: Container eaa62ff2df11547744c5f7cf82cad16bf576820d2a209c4f19f173cca68f5511 is not running
$
Could it be that the container only runs for a very short time? If you use the -a flag in your statement to get only active containers, like so:
docker ps -a
Does it still show up? It could be that it runs and just uses something like ECHO. In that case, because the program run succesfully the container is immediately terminated.
Is this an official image? If so, try to run the container without the -d (for deamon) flag. This should output the run information to terminal and give you some information on what is going on.
sudo docker exec -it eaa62 bash
Related
I ran a docker container on one of the terminals, on the other terminal:
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80b6be3a7d56 rbonghi/isaac-ros-tutorial:realsense-camera "/ros_entrypoint.sh …" 9 seconds ago Up 8 seconds inspiring_almeida
and then I run
$ docker attach inspiring_almeida
now nothing seems to happen, cursor moves to a new line.
$ docker attach inspiring_almeida
What am I doing wrong? I expected to see something like root#80b6be3a7d56
P.s. I'm accessing the machine that I run docker via SSH - if that matters.
Run docker exec -it inspiring_almeida /bin/bash. It runs a shell inside the container.
attach just connects your input/output terminal with the container's input/output.
I am trying to get a Docker Container running. I am following this guide: http://opendata.cern.ch/docs/cms-guide-docker.
The container refuses to start and give me access to the shall I expect.
Running the following command (as mentioned in the guide) does nothing, the process exits with a non-0 exit code. The first time I ran it, it downloaded the container image but did not land me into the sell as the guide says it would.
$ docker run --name opendata-2010 -it cmsopendata/cmssw_4_2_8 /bin/bash
I can see the container, it exits soon as it starts.
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be670158d200 cmsopendata/cmssw_5_3_32 "/opt/cms/entrypoint…" 34 minutes ago Exited (139) 3 seconds ago opendata
These are other things I have tried to no avail.
$ docker exec -it be670158d200 /bin/bash
Error response from daemon: Container be670158d200ae85871fbda810fa6074dcb7bc8fc606f000710f630add1b80b6 is not running
$ docker start --attach be670158d200
failed to resize tty, using default size
My question is similar to this: Docker - Container is not running, but I know that unlike in that question, here I should be getting the shell.
I am running this in Windows Subsystem for Linux 2 - Ubuntu 20.04, docker version 19.03.8 - build afacb8b7f0. Any help is greatly appreciated, thanks.
I had the same error with below logs
dockerd[15309]: time="2022-01-11T11:13:35.133154132+05:30" level=error msg="Handler for POST /v1.41/exec/94553dc2f9aaa3c1245df7384138786a8a576af99105a285258fce8b980b4660/resize returned error: timeout waiting for exec session ready"
This is a bug in docker 20.10 version and can be solved by downgrading containerd rpm
Removed:
containerd.io.x86_64 0:1.4.4-3.1.el7
Installed:
containerd.io.x86_64 0:1.4.3-3.1.el7
I'm new to docker.
I have an image that I want to run, but I want docker to see if that image is already running from another terminal...if it is running I don't want it to load another one...
is this something that can be done with docker?
if it helps, I'm running the docker with a privileged mode.
I've tried to search for singleton docker or something like that, but no luck.
updates-
1.working from ubuntu.
My scenario- from terminal X I run docker run Image_a
from terminal Y I run docker run Image_a
when trying to run from terminal Y, I want docker to check if there is already a docker running with Image_a, and the answer is true - I want docker not to run in terminal Y
You can use the following docker command to get all containers that running from specific image:
docker ps --filter ancestor="imagename:tag"
Example:
docker ps --filter ancestor="drone/drone:0.5"
Example Output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3fb00087d4c1 drone/drone:0.5 "/drone agent" 6 days ago Up 26 minutes 8000/tcp drone_drone-agent_1
This approach uses docker api and docker daemon, so it doesnt matter if the run command executed in background or other terminal.
Aother approach:
If you have a single container form a single image:
Try naming your containers, You cant have 2 containers with the same name:
docker run --name uniquecontainer Image_a
Next time you run the above command you will get an error. Btw consider using -d so you dont have to switch terminals.
docker run -d --name uniquecontainer Image_a
I launch a docker container from an image with the following command:
$ docker run -d myimage /bin/bash -c "mycommand"
When "mycommand" is finished, the container is stopped (I suppose it is stopped), but it is not deleted, because I can see it with this command:
$ docker ps -a
Is there any way to restart this container with the same parameters and keep data generated by mycommand?
Yes, when the initial command finish its execution then the container stops.
You can start a stopped container using:
docker start container_name
If you want to see the output of your command then you should add -ai options:
docker start -ai container_name
PS. there is a docker restart container_name but that is used to restart a running container - I believe that is not your case.
First, $ docker ps -a shows all containers (the ones that are running and the stopped ones), so that is the reason you are not seeing your stopped container listed.
Second, you can easily start a stopped container running:
$ docker start container_name
Once the container has been started, you can run your command by:
$ docker exec -it container_name bash -c "mycommand"
The stuff you create in your container will remain inside your container as long as it exists. If you want to keep data even if your container is removed you can use a volume.
It should be
$ docker restart container_id # OR
$ docker restart container_name
From the above picture we see one container is up and other status is Exited.
When a container is exited we can still start it back up, because a container stop doesn't mean that it's like dead or cannot be used again we can very easily stop and then start containers again at some point in the future. To start a container backup we can take it's ID and then execute docker start and paste the ID end.
sudo docker start container_id
command for exited container in the above picture will be.
sudo docker start -a bba606a95392
Out put:
By the way: While restarting a container we can not replace the default command, as soon as you started up with the default command is set for the container, for example if we start our container overriding the default command let's see what happened:
Docker is thinking we are trying to start and attach multiple container at the same time.
So when we up a container and let it exit, we can start it back up again which is going to reissue the default command that was used when the container was first created. It is part of docker container lifecycle.
Unfortunately, if you restart your VM/System and it shows
mysql-tls:5.7 "docker-entrypoint.s…" 18 hours ago Exited (255) 44 seconds ago
Answer :
Start the Container
docker start mysql
or
docker start your_container_name
This question already has answers here:
How to continue a Docker container which has exited
(14 answers)
Closed 6 years ago.
A related question & answer on How to start a docker container (ubuntu image) suggest using docker run -it ubuntu to start a ubuntu container and connect to it. However the run command creates and starts a new ubuntu container.
How do we start an existing docker container (ubuntu image) given it's CONTAINER_ID without creating a new container?
Example:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f297d02f419 ubuntu "/bin/bash" 3 seconds ago Exited (0) 1 seconds ago cranky_wilson
How do we start 9f297d02f419 ?
you can start the stopped container using docker start command -
eg:
docker start 9f297d02f419
If you just use run on the Ubuntu image it will start a container that's running no command, which will immediately stop. You can docker start it but it will stop again. You can see it with docker ps -a.
The accepted answer in that question is very old and not very good. If you run that command on the current Docker version you get an error No command specified!
What you need to do is tell that container to run a command:
docker run ubuntu date
Will run a container from the image, run the date command, then exit. If you want to keep it running indefinitely, try something like:
docker run -d ubuntu tail -f /dev/null
You should see that the container is now running. The -d makes it run in the background, otherwise it will occupy your shell. And the final piece of the puzzle: since we have a container now that's configured to run a command, you can use docker ps to find its ID, and you can docker stop and docker start it at will.