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.
Related
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 run the tomcat server 8 in docker, it runs correctly when I run using docker run command and the command prompt don't come back, now I press ctrl+c and prompt come back, but now tomcat server has stopped so when I check on http://localhost:8080 the tomcat page not appear. So how to make it run continuously or so called system level process in container.
Here is my docker file. Help me with this
FROM scratch
FROM ubuntu:16.04
RUN mkdir /opt/java8
RUN mkdir /opt/tomcat8
ENV JAVA_HOME /opt/java8
ENV CATALINA_HOME /opt/tomcat8
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
ADD jdk1.8.0_112 /opt/java8
ADD apache-tomcat-8.0.38 /opt/tomcat8
ADD M_UserTP.war /opt/tomcat8/webapps
EXPOSE 8080
CMD ["catalina.sh", "run"]
Running startup.sh not even help me.
docker run distinguishes between a foreground and a detached mode (source). Your troubles are caused by the fact that you run the container in foreground mode. To run it in the background as a daemon, use the detached mode:
docker run -d [IMAGE] [COMMAND]
This starts the container in the background, and keeps it running as long as the process inside continues to run. You can see what's going on inside the container by either looking at its logs (docker logs [CONTAINER_ID]) or by jumping on a shell inside the container (docker exec -it [CONTAINER_ID] /bin/sh).
If you are done working with the container, use docker stop [CONTAINER_ID] to stop it. If you are unsure whether you have a container running, use docker ps.
Instead of ctrl + c, you should type ctrl + p and ctrl + q to detach
There are 2 ways to get into a running container:
1) Attach to the process/container
Used to attach your terminal’s standard input, output, and error to a running container using the container’s ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.
To stop a container, use CTRL-c. This key sequence sends SIGKILL to the container. You can detach from a container and leave it running using the CTRL-p CTRL-q key sequence.
# docker run -it ubuntu:15.0 /bin/bash
root#9391b08536ae:/#
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9391b08536ae ubuntu:15.0 "/bin/bash" 6 seconds ago Up 6 seconds 0/tcp confident_albattani
# docker attach 939
root#9391b08536ae:/#
root#9391b08536ae:/# exit
exit
root#labadmin-VirtualBox:~/RAGHU/python# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2) Execute the container
The docker exec command runs a new command in a running container.
# docker exec -it 939 /bin/bash
root#9391b08536ae:/# exit
exit
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9391b08536ae ubuntu:15.0 "/bin/bash" 25 seconds ago Up 25 seconds 0/tcp confident_albattani
Hope this helps.
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
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.