What does COMMAND in 'docker ps' mean? - docker

docker ps or docker container ls returns an overview of all running containers. The meaning of all columns is clear to me, except one. What does the column 'COMMAND' mean?

This is the command which is passed to the container.
$ docker run -d busybox top
$docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3eca7c034b21 busybox "top" 6 seconds ago Up 5 seconds recursing_dirac
If you check above, top is the command which has been passed to the busybox container and that's what it's showing in the docker ps -a.

It's the command passed to docker run <image> [command].
$ docker run -d ubuntu sleep 60
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
f0c9cd92a938 ubuntu "sleep 60" 3 seconds ago Up 1 second
If no command was specified there then it's the CMD from the Dockerfile. In ubuntu's case that would be CMD ["/bin/bash"]:
$ docker run -di ubuntu
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
9cd752ee86f4 ubuntu "/bin/bash" 4 seconds ago Up 2 seconds

Related

How do I inspect the stopped docker container files

Step 1:
docker ps -a
container Id: dd5cf6b519b4
I need to inspect inside the stopped docker container which is cannot start.
I tried with docker exec -it container-id bin/bash But this is for running container.
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
0dfd54557799 ubuntu "/bin/bash" 25 seconds ago Exited (1) 4 seconds ago peaceful_feynman
Commit the stopped image
$ docker commit 0dfd54557799 debug/ubuntu
now we have a new image
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
debug/ubuntu <none> cc9db32dcc2d 2 seconds ago 64.3MB
create a new container from the "broken" image
$ docker run -it --rm --entrypoint sh debug/ubuntu
inside of the container we can inspect - for example, the file system
$ ls /app
App.dll
App.pdb
App.deps.json
You can start container with specific entrypoint
docker run --entrypoint sleep YOUR_IMAGE 3600
It will block current terminal for 3600 seconds. You can open new terminal tab(do not close current one) and you can verify if your container is working with the
docker ps
If you do not want to block current terminal, you can add -d flag to docker run:
docker run -d --entrypoint sleep YOUR_IMAGE 3600
Above command will start docker which will be doing nothing, then you can ssh into the container when it is working with
docker exec -ti CONTAINER HASH sh

How to start the stopped ubuntu container in docker? (ran without options (-i - t) )

How to start the stopped ubuntu container in docker? any idea?
$docker pull ubuntu
$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 7698f282e524 29 hours ago 69.9MB
$docker run ubuntu
$docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
512009f5b00e ubuntu "/bin/bash" 39 minutes ago Exited (0) About a minute ago sad_noether
$docker start sad_noether
sad_noether
$docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
512009f5b00e ubuntu "/bin/bash" 40 minutes ago Exited (0) 23 seconds ago sad_noether
$docker exec -it sad_noether bash
Error response from daemon: Container 512009f5b00e6be5e3ee199d2db25c628219c237b16e37eed5cb6052179ebdbc is not running
How to start the stopped ubuntu container in docker?
docker start CONTAINER
In your case, you ran ubuntu without any foreground process, so the container exits immediately when you start it.
You should run docker run -it ubuntu bash
You should run this to keep the container running.
docker run -d ubuntu sleep 9999999
docker run -it centos /bin/bash
to run the container the first time and exit.
docker ps -a
to see that container is stopped.
docker start -ai [CONTAINER_ID]
to start the existing container.
You are into the container!

Docker Error: No such container: friendlyhello

I'm trying to stop and remove a docker - container.
I started with docker turorial part1, now part2 from here: https://docs.docker.com/get-started/part2/#run-the-app
I copied souce from there. and its also available here: https://gist.github.com/sl5net/8b510bc0d3e00c474575e010003406c1
Here you could see how my console looks like:
Microsoft Windows [Version 10.0.16299.431]
C:\fre\private\docker\test18-05-14_05-27>docker build -t friendlyhello .
Sending build context to Docker daemon 5.12kB
no matching manifest for windows/amd64 in the manifest list entries
BTW solution: I swaped to linux container (right click>contextmenu on docker icon)
C:\fre\private\docker\test18-05-14_05-27>docker build -t friendlyhello .
... Successfully built itsdangerous MarkupSafe
Successfully tagged friendlyhello:latest
C:\fre\private\docker\test18-05-14_05-27>docker run -p 4000:80 friendlyhello
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
C:\fre\private\docker\test18-05-14_05-27>docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
friendlyhello latest 7d4d1e0f78e6 8 minutes ago 151MB
python 2.7-slim 46ba956c5967 9 days ago 140MB
C:\fre\private\docker\test18-05-14_05-27>docker container stop friendlyhello
Error response from daemon: No such container: friendlyhello
C:\fre\private\docker\test18-05-14_05-27>docker rm -f friendlyhello
Error: No such container: friendlyhello
There is no container available with the name friendlyhello as you are simply running the container using docker run -p 4000:80 friendlyhello, here friendlyhello is the name of the image, and not the container's name.
Either run that container by giving it a name like below:-
docker run -p 4000:80 --name SOMENAME friendlyhello
In this case you will be able to stop and remove that container using the below command
# container stop
docker container stop SOMENAME
# container removal
docker rm -f SOMENAME
Or if running without giving a name to the container, you will have to use the ID of the container in the commands to stop and remove, even in various other commands you will be using the ID to refer that con
The tutorial shows:
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED
1fa4ab2cf395 friendlyhello "python app.py" 28 seconds ago
You haven't added a name (tag) to your container, so you must use its ID to stop it:
docker container stop 1fa4ab2cf395
friendlyhello is the name of the image, not the container.
See docker run --name to give it a name.
If you don't have a name, you will the ID with docker ps -a
The OP adds:
using docker stop 8e008ebf3ad7 its out of list using: docker container ls buts stays in list using: docker ps -a
docker stop 8e008ebf3ad7
8e008ebf3ad7
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
5227976cb9bb friendlyhello "python app.py" About an hour ago Up About an hour 0.0.0.0:4001->80/tcp SOMENAME
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
5227976cb9bb friendlyhello "python app.py" About an hour ago Up About an hour
0.0.0.0:4001->80/tcp SOMENAME
8e008ebf3ad7 friendlyhello "python app.py" 6 hours ago Exited (137) About an hour ago
That is expected: a stop will put a container in an "Exited" state, which is handy when you want to debug a container which stopped without your consent!
You can then do a docker container rm <ID> in order to reomve it from the docker ps -a list.
Note that if you had launch your container with docker run --rm ..., a stop would have stopped and removed (deleted) the container directly.
docker pull solr => to pull the docker image
docker run -p 8983:8983 -t solr => run the image and define the port
http://localhost:8983/ - run on local web browser

Create new image based on standard one

I have installed Docker and have running some Ubuntu image with command:
sudo docker run ubuntu
I would like to create some text file on it and find it next time the same image will run. How to achieve that?
UPD.
Got problems with attaching to docker.
I have running docker
docker ps -a
aef01293fdc9 ubuntu "/bin/bash" 6 hours ago Up 6 hours priceless_ramanujan
Since it is Up mode, I suppose I don't need to execute command:
docker start priceless_ramanujan
So, I run command attach
docker attach priceless_ramanujan
And got nothing in output while command not returns.
Why I can't get to container's bash?
Simple example:
$ docker run -it ubuntu
root#4d5643e8c1a8:/# echo "test" > test.txt
root#4d5643e8c1a8:/# cat test.txt
test
root#4d5643e8c1a8:/# exit
exit
$ docker run -it ubuntu
root#cdb44750bffc:/# cat test.txt
cat: test.txt: No such file or directory
root#cdb44750bffc:/#
docker run image_name
This command creates and starts a new container based on the provided image_name. If a name is not set for the container, a random one is generated and assigned by docker. In the above example 2 containers were created based on ubuntu.
with docker ps -a we can see that modest_jennings and optimistic_leakey are the random names created:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cdb44750bffc ubuntu "/bin/bash" About a minute ago Exited (1) 4 seconds ago optimistic_leakey
4d5643e8c1a8 ubuntu "/bin/bash" 2 minutes ago Exited (0) 2 minutes ago modest_jennings
cat test.txt failed the 2nd time because the file didn't exist. The container started from a "clean" ubuntu image.
Actually, we created test.txt inside modest_jennings only.
docker start container_name
This command starts a stopped container. So, in our case, the file is still there:
$ docker start modest_jennings
modest_jennings
$ docker attach modest_jennings
root#4d5643e8c1a8:/# cat test.txt
test
root#4d5643e8c1a8:/#
docker commit container_name image_name
This command is to create a new image, so that you can use it later and run containers based on that image. Continuing our example...
$ docker commit modest_jennings my_ubuntu
sha256:a4357f37153ac0b94e37315595f1a3b540538283adc3721df4d4e3b39bf8334f
$ docker run -it my_ubuntu
root#2e38616d532a:/# cat test.txt
test
root#2e38616d532a:/#
If you want a custom image, you can create a Dockerfile
`FROM ubuntu:16.04
ADD ./test.txt /tmp/`
after you can build it docker build -t ubuntu:custom .
and finally run your custom image docker run --name myubuntu ubuntu:custom sleep 3000
You can check your file with docker exec -it myubuntu /bin/bash and more /tmp/test.txt

How to start a docker container (ubuntu image)

How to stat a docker container. I had created it using
docker run -d -P -v /Users/bsr:/usr/local/users --name test ubuntu
I do have virtual box guest addition installed, and mounting works. But, I am not sure why I can't I keep the shell running.
bsr[~/tmp/web] $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf620ff6c36a ubuntu:latest "/bin/bash" 2 hours ago Exited (0) 2 minutes ago test
8213c8d49842 nginx:latest "nginx" 3 hours ago Up About an hour 0.0.0.0:49154->80/tcp web
bsr[~/tmp/web] $ docker start test
test
bsr[~/tmp/web] $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf620ff6c36a ubuntu:latest "/bin/bash" 2 hours ago Exited (0) 2 seconds ago test
8213c8d49842 nginx:latest "nginx" 3 hours ago Up About an hour 0.0.0.0:49154->80/tcp web
bsr[~/tmp/web] $
Edit:
it may be because the command (/bin/bash ??) finishes immediately. When I tried,
docker run -d -P -v /Users/bsr:/usr/local/users --name test5 ubuntu /bin/bash -c "while true; do echo Hello world; sleep 1; done"
I could get the terminal. But isn't there any way to just start a container and get to the terminal ??
If you want to run an interactive process, you should use the -i (keep stdin open in case you detach) and -t (allocate a pseudo-tty) flags:
docker run -it ubuntu
You can look at the docs for more information on those flags and their usage.
You can start by using simple command.
docker run "CONTAINER_ID"

Resources