How to restart my Docker container? - docker

This is what ps -a gives us
NAMES
4514ea1b7b22 debian "--name gallant_spen…" 9 minutes ago Created peaceful_engelbart
df9bd2731a2b debian "--name gallant_spen…" 9 minutes ago Created happy_hodgkin
dd5b1f1b39ec redis "docker-entrypoint.s…" 32 minutes ago Up 31 minutes 6379/tcp myred
ffd6ef9d8bd5 redis "docker-entrypoint.s…" 32 minutes ago Exited (127) 32 minutes ago festive_jennings
9d01d321adad redis "docker-entrypoint.s…" 33 minutes ago Exited (0) 32 minutes ago agitated_shannon
eb7c13e7cdee debian "ls /data" 2 days ago Exited (0) 9 seconds ago gallant_spence
8991a31b1e38 debian "ls /data" 2 days ago Exited (0) 2 days ago determined_minsky
I have tried in this manner
docker start `docker ps -q -l` gallant_spence
But error ocurrs
Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"--name\": executable file not found in $PATH": unknown
gallant_spence
Error: failed to start containers: 4514ea1b7b22
I am interested in data volume that has been mounted in my previous work on this container
"Mounts": [
{
"Type": "bind",
"Source": "/home/mm/code/lesson_04",
"Destination": "/data",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
If I try
mm#6830s:~$ docker start -ai gallant_spence
one_sample.py
parallel_series.py
Python files are added to data folder so I thought that it worked.Then I try again
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd5b1f1b39ec redis "docker-entrypoint.s…" About an hour ago Up About an hour 6379/tcp myred
Hot to fix this?

You start a stopped container with
docker start [OPTIONS] CONTAINER [CONTAINER...]
For your case, you can use:
docker start gallant_spence or
docker start eb7c13e7cdee
As it is shown by the docker ps -a result, your container is configured with this CMD:
"ls /data"
This means that every time you start your container, this command will run and the container will then exit. This is how containers work. When their primary process finishes, they exit.
About the error you get and docker ps -q -l:
-q (from "quiet") tells the command to only print the container IDs
-l (from "last") tells the command to print the latest created container
This means that the above command brings you back: 4514ea1b7b22. If we put together all things...
your command:
docker start `docker ps -q -l` gallant_spence
turns to:
docker start 4514ea1b7b22 gallant_spence
The fail message you get is for 4514ea1b7b22 because it doesn't have a CMD set properly to start. I see something like: --name gallant_spen…

Related

Docker fails to start container in detached mode

I have a Google VM that i am trying to start a container, that will start up a web server.
Since i want to be able to do other things with my terminal, i tried starting the container in detached mode.
This is what i typed:
sudo docker run -d -p 5001:5001 -v $(pwd):/mnt/translation -w="/mnt/translation" -e "TERM=xterm-color" f_translate
After this, i get back a string
9f8cc86f1e4a262bff8ff4f40f1a9036c686472b0ec3fded84980a60d26f6980
However, i couldn't connect to the server with docker exec.
I typed docker ps, to see all running containers, but there are none running.
EDIT:
This is the result of the docker ps -a:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9f8cc86f1e4a f_translate "/bin/bash" 28 minutes ago Exited (0) 28 minutes ago reverent_sinouss
i
faeec783edce f_translate "/bin/bash" 37 minutes ago Exited (0) 37 minutes ago adoring_chaum
1b96a5117aef f_translate "/bin/bash" 25 hours ago Exited (129) 24 hours ago xenodochial_noet
her
b364de5733b9 f_translate "/bin/bash" 41 hours ago Created nice_lumiere
5b042e459548 f_translate "/bin/bash" 41 hours ago Exited (0) 41 hours ago hardcore_elbakya
n
ea97b56d6822 f_translate "/bin/bash" 42 hours ago Created practical_lumier
e
2392c2b074a1 f_translate "/bin/bash" 42 hours ago Created hardcore_easley
e24c579f3094 f_translate "/bin/bash" 42 hours ago Created inspiring_merkle
3e4e412c551b f_translate "/bin/bash" 42 hours ago Created crazy_engelbart
8c198931c560 f_translate "/bin/bash" 42 hours ago Exited (0) 41 hours ago hardcore_cannon
67c5ad80b074 f_translate "/bin/bash" 42 hours ago Exited (0) 42 hours ago dreamy_margulis
b2b8773a9d77 a2f276018a81 "/bin/bash" 42 hours ago Exited (127) 42 hours ago jolly_greider
2c3c74ee073c a2f276018a81 "/bin/bash" 42 hours ago Exited (0) 42 hours ago pensive_chandras
ekhar
8563a35a96a7 cq_image "/bin/bash" 47 hours ago Exited (127) 46 hours ago gallant_rubin
44431d47308c cq_image "/bin/bash" 2 days ago Exited (129) 2 days ago peaceful_tesla
When i type docker logs 9f8cc86f1e4a262bff8ff4f40f1a9036c686472b0ec3fded84980a60d26f6980, i get nothing back.
You're run the container only with the bash command. This command returns exit code 0 immediately after the run. Then container finishing the work.
You have to run the container with some process that not returns the exit code right after a run.
This is a normal behavior that container finishing work when the job is finished with the success or with the error.
It seems as if there is a need to explain what containers do:
Containers have been designed to do one job. You tell them which command to execute and they will do that until it is done. Usually this is specified within a Dockerfile, in there you can define ENTRYPOINT and CMD to tell the container what to do when starting up. The container will then do that particular job until its done and then shut down.
And that's the case with your container. Your container executes the command /bin/bash as can be seen in the COMMAND column of the docker ps -a output.
So it actually is doing what it is supposed to do. It simply is executing the bash and since the command finished at that point it is shutting down, therefore you cannot connect to it anymore.
To be able to exec into a container it must be up and running, to do so you will have to change the entrypoint of your container. You can either do so by building a new image via a Dockerfile or you can overwrite it on the fly with the docker run command.
For debugging purposes, especially when wanting to exec into the container manually, you are most likely going to choose a command that does nothing but runs forever, perhaps something like sleep infinity.
TL;DR
With docker run after mentioning the image name you can define which command the container shall execute when starting up.
Execute the following command to ensure that your container does not exit immediately:
sudo docker run -d -p 5001:5001 -v $(pwd):/mnt/translation -w="/mnt/translation" -e "TERM=xterm-color" f_translate /bin/sh -c sleep infinity

What are the extra containers removed by "docker container prune" not listed by "docker ps -a"?

~/tmp/Counter1 ⌚ 10:18:24
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a46d397337e6 xx "echo ls" 20 hours ago Exited (0) 20 hours ago cranky_snyder
28d7339e57aa bf3a41a4ae8f "/bin/sh -c 'echo $e…" 21 hours ago Exited (0) 21 hours ago unruffled_archimedes
~/tmp/Counter1 ⌚ 10:18:27
$ docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
a46d397337e68101fe983f354f87e8b4c0e086a4157dce7e7c4a2558105da525
28d7339e57aa222697851aaf4fdd36da2cbbc16f5fa9d4373ac499f8f8e15de5
a3cf99470e2f6e623c97db14249fa14e0afe9fd01eaac1ef6087ef98575f3690
5123adaa9fab02346c589aa23d3dd1eae1085138ec0e9cb23f388bbc5d668a92
45727d359ea4a036dd466f72fbaa750b135244d730b514c63a96518c71b4ad90
3260c4155074df32038ee31273e7059c1755fe6145b98d187ca006e1a39c3636
7d9c83d179932b1c97d43077cfe19fb6bcac123e295affcfa4cc791c43ddf513
3e32ee26e2e91ffc704cb27069cddf8f2f576ca407b4d8969e528c5a229cd855
46e8782774e2a6d5c8885fa5710134e1cc26e4abd75f29d883e4b32abec07d82
4728995a0162a033869e9fdd306435b1365309da643b2bcfa708c04839e7993c
Total reclaimed space: 0B
If I repeat the same thing, I see the right number of docker container removed. But after some time of playing with more containers, I again see a similar mismatch in the number of containers.
If I understand correctly, docker ps -a should show me all containers. Wonder what the other SHAs are from?

Ports not accessable

I installed docker and issues a 'docker swarm init' command.
I'm trying to launch a stack using the following command: docker stack deploy -c docker-compose.yml mystack
The docker-compose file can be found here, the first docker file here and the second here
The output of 'docker ps' is:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f582b3e8d33e tons/ip2country:latest "/bin/sh -c 'java -D…" 8 seconds ago Up 6 seconds 8080/tcp ip2flag_country-service.1.t5rvuqaw8tj7v20u0xo0dgy6x
bbf2c8304f1a tons/ip2flag:latest "/bin/sh -c 'java -D…" 10 seconds ago Up 8 seconds 8080/tcp ip2flag_app.1.z00gz8adj2yshpgimaw2o55d3
cbc7eaace4bf portainer/portainer "/portainer" 39 minutes ago Up 39 minutes 0.0.0.0:9000->9000/tcp portainer
The output of 'docker service ls' is:
ID NAME MODE REPLICAS IMAGE PORTS
ex51pyh1oyyo ip2flag_app replicated 1/1 tons/ip2flag:latest *:8080->8080/tcp
yhbt97lmjqan ip2flag_country-service replicated 1/1 tons/ip2country:latest
Since I'm running this on localhost I'd expect http://localhost:8080/ to return some sort of data. But it just times out. If I attach to the container and execute something like wget localhost:8080/some/path it works as expected. So the service is running and within the container listening to port 8080. However the port isn't exposed outside of dockers net. Further more I can add that launching with 'docker-compose up' works just fine too. But not with 'docker stack deploy'. Any clue about what I'm doing wrong?

Why does the name column of the docker ps -a always different

I was just playing around with docker!!
Ran ps command -a option
docker run -a
C:\Users\sarkan1>docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3d6db385321c busybox:1.24 "sleep 1000" 26 seconds ago Up 24 seconds lucid_ramanujan
e6acd65398b2 hello-world "/hello" 43 minutes ago Exited (0) 43 minutes ago nifty_brattain
c5576137580d hello-world "/hello" 4 days ago Exited (0) 4 days ago dreamy_aryabhata
2594fbf1fa82 hello-world "/hello" 4 days ago Exited (0) 4 days ago nostalgic_hopper
c0102bc64c45 hello-world "/hello" 4 days ago Exited (0) 4 days ago vibrant_khorana
c4af79ea96e9 hello-world "/hello" 4 days ago Exited (0) 4 days ago cranky_heyrovsky
Questions :
Why did I get the values in the names column always different? I ran the same container I guess!!
What is command column? Does the slash before the hello (/hello) have any significance?
Unless you launch a container specifying its name (docker run --name), docker will generate one for you.
That is easier than referencing said container with its ID.
You can then make docker commands with its (generated) name instead.
See more at "How does Docker generate default container names?".
(and the source code: moby/moby pkg/namesgenerator/names-generator.go)
The command column is the full command executed by the container: once this command stops, the container stops.
That command is specified in the docker image, and is a combination of:
Dockerfile ENTRYPOINT
Dockerfile CMD
(See "difference between cmd and entrypoint in dockefile")
Basically they are random container names generated!! The left and right parts of the names are hardcoded and can be found in
https://github.com/moby/moby/blob/master/pkg/namesgenerator/names-generator.go
Docker engine generates it if default name is not provided when you create a new docker container.

I run a docker container,but after few minutes , it was killed by himself

I have run a docker container and using nsenter into it.But after few minutes,this container was killed by himself
root#n14:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e69069513c8b sameersbn/mysql "/start" 25 minutes ago Up 12 seconds 3306/tcp mysqldb1
02f3f156b3e7 sameersbn/mysql "/start" 25 minutes ago Up 25 minutes 3306/tcp mysqldb
root#n14:~# nsenter --target 13823 --mount --uts --ipc --net --pid
root#e69069513c8b:/home/git/gitlab# Killed
root#n14:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e69069513c8b sameersbn/mysql "/start" 55 minutes ago Exited (0) 28 minutes ago mysqldb1

Resources