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.
we have Linux machine with the following container
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6de660db9fdb kafka-exporter:v1.9.0 "/bin/kafka_export" 23 hours ago Up 17 hours kafka-export
we want to kill the container so we did that:
docker kill 6de660db9fdb
but its hang for along time ( more then hour and not killed )
any advice how to stop/kill the container ?
You could try restarting the Docker service first:
sudo systemctl restart docker
And then removing the container with the force -f flag:
sudo docker rm -f 6de660db9fdb
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
I created a docker container that is already running a the bash.
$ docker run -ti ubuntu bash
In a new terminal I check for the running containers:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
354449b423e1 ubuntu "bash" About a minute ago Up About a minute backstabbing_mestorf
Now I want to mount a drive that I have shared already on the running container without committing and creating a new image, neither pausing nor stopping it.So, I know
$ docker run ti -v /SrcDir:/Dest bash
The command above will create a new container but I don't want that. Is there a way where I will be able to mount and eject volumes from the host onto a running container?
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