Alpine 3.6 Docker container error on stop (exit code 137) - docker

Container running on Ubuntu 16.04
Below how I do (Random name sad_wiles created):
docker run -it -d alpine /bin/ash
docker run -it -d alpine /bin/sh
docker run -ti -d alpine
docker start sad_wiles running fine and I can enter & exit sh
However, docker stop sad_wiles giving exit code 137. Below is the log:
2017-11-25T23:22:25.301992880+08:00 container kill 61ea1f10c98e2462f496f9048dcc6b45e536d3f7ba14747f7f22b96afb2db60d (image=alpine, name=sad_wiles, signal=15)
2017-11-25T23:22:35.302560688+08:00 container kill 61ea1f10c98e2462f496f9048dcc6b45e536d3f7ba14747f7f22b96afb2db60d (image=alpine, name=sad_wiles, signal=9)
2017-11-25T23:22:35.328791538+08:00 container die 61ea1f10c98e2462f496f9048dcc6b45e536d3f7ba14747f7f22b96afb2db60d (exitCode=137, image=alpine, name=sad_wiles)
2017-11-25T23:22:35.547890765+08:00 network disconnect 3b36d7a71af5a43f0ee3cb95c159514a6d5a02d0d5d8cf903f51d619d6973b35 (container=61ea1f10c98e2462f496f9048dcc6b45e536d3f7ba14747f7f22b96afb2db60d, name=bridge, type=bridge)
2017-11-25T23:22:35.647073922+08:00 container stop 61ea1f10c98e2462f496f9048dcc6b45e536d3f7ba14747f7f22b96afb2db60d (image=alpine, name=sad_wiles)

This is not an error as mentioned in the comment by #yament You'll see this exit code when you do a docker stop and the initial graceful stop fails and docker has to do a sigkill. As mentioned here, it's a linux standard: 128 + 9 = 137 (9 coming from SIGKILL).
You can increase your memory limit in Docker App > Preferences > Advanced on Mac os. As changing this mem_limit=384m to 512m works. Here is additional resunce will help you, Exit Status

If you are curious about how sad_wiles name appeared as your container name, that has been a Docker feature from early days. If you do not specify a name for your Docker container using --name tag with your Docker run command, Docker will create a name for the container based on an open source list of scientist and hackers. You can get its source code from here.
The signal code issue may be due to the memory limit is low for Docker. A github issue was also opened on this. Refer it from here. Try changing the memory allocation for Docker as the comments for the attached github issue recommend.

Related

What to do if the docker container hangs and does not respond to any command other than ctrl+c?

I have been running a nvidia docker image since 13 days and it used to restart without any problems using docker start -i <containerid> command. But, today while I was downloading pytorch inside the container, download got stuck at 5% and gave no response for a while.
I couldn't exit the container either by ctrl+d or ctrl+c. So, I exited the terminal and in new terminal I ran this docker start -i <containerid> again. But ever since this particular container is not responding to any command. Be it start/restart/exec/commit ...nothing! any command with this container ID or name is just non-responsive and had to exit out of it only after ctrl+c
I cannot restart the docker service since it will kill all running docker containers.
Cannot even stop the container using this docker container stop <containerid>
Please help.
You can make use of docker RestartPolicy:
docker update --restart=always <container>
while mindful of caveats on the docker version you running.
or explore an answer by #Yale Huang from a similar question: How to add a restart policy to a container that was already created
I had to restart docker process to revive my container. There was nothing else I could do to solve it. used sudo service docker restart and then revived my container using docker run. I will try to build the dockerfile out of it in order to avoid future mishaps.

Can't get my Docker Container to start and give me a shell

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

Build docker ubuntu image by Dockerfile

If command "docker run ubuntu bash" the container won't last.
but if I command "docker run -it ubuntu bash"
the container will make a pseudo-tty and keep this container alive.
my question is
is there any way I can make a Dockerfile for building an image based on ubuntu/centos then I just need to command "docker run my-image" and
the container will last.
apologize for my poor english, I don't know if my question is clear enough.
thanks for any response
There are three ways to run containers:
task containers - do one thing and then exit, like docker run ubuntu ls /
interactive containers - open a connection to the container with -it, like docker run -it ubuntu bash
background containers - keep a container running detached in the background with -d, like docker run -d ubuntu:14.04 ping localhost
Docker keeps the container running as long as there is an active process in the container. The first container exits when the ls command completes. The second container will exit when you exit the bash session. The third container will stay running as long as the ping process keeps running (note that ping has been removed from the recent Ubuntu images, which is why the example specifies 14.04).

Docker SSH or Detach/Attach

I have a docker image with all the necessary tools and environment properly set up. However, I am having a hard time running it in the background.
Seems like there are two approaches:
(1) can run the box as daemon and I can attach to it whenever I want to use the box. However, the container exit with code zero right after I run it as daemon.
$:~/docker/docker_scrapy$ sudo docker run -ti -v ~/docker/docker_scrapy/myvolume:/var/myvolume 3fb9894af1d9 /bin/bash
root#3fc39116a586:/# python -c 'from bs4 import BeautifulSoup'
root#3fc39116a586:/# cd /var/myvolume/
root#3fc39116a586:/var/myvolume#
$:~/docker/docker_scrapy$ sudo docker run -d -v ~/docker/docker_scrapy/myvolume:/var/myvolume 3fb9894af1d9
c5fab6e6ac02a579e3371aa641b18ca67feb93a9f4f4934b6d083157182fe4e1
$:~/docker/docker_scrapy$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Clearly, I can start the box in the interactive mode, but when I try to run it as a daemon, it will exit with code 0 right after I started. And I can not attach to it because I need to start it. Does that mean you can not run a image in the daemon mode if it is idle?
(2 )Or setting it up as a SSH server, and I can ssh in and do the work whenever I want. Like Vagrant up/ssh..
In summary:
(1) What did I do wrong with the detach/attach?
(2) Which is the proper way to have a run docker in the background? daemon/ssh
If you give it another command to run after starting the service that waits for input then the container will keep running until you attach and exit that command. I usually leave a shell running after the service starts so I can debug things. here's a simple example:
First let's create a service that runs in the background
arthur#a:~$ docker run -ti ubuntu bash
root#5dc7f330b947:/# cat <<'EOF' >start-service.sh
> while true
> do
> echo service is running >> service.log
> sleep 10
> done
> EOF
root#5dc7f330b947:/# chmod +x start-service.sh
root#5dc7f330b947:/# exit
arthur#a:~$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5dc7f330b947 ubuntu:12.04 bash 50 seconds ago Exited (0) 3 seconds ago jolly_nobel
arthur#a:~$ docker commit 5dc7f330b947 service/example
4c37b69b129287d79a6fe3916e4293f935194966b1de49d125f1cf8d6ab14f6f
then we can start it (i background it with a & here. in your example the & would not be required). Note it's fine to use both the interactive and detach options.
arthur#a:~$ docker run -ti -d service/example bash -c "./start-service.sh & bash"
b35a5397ea2d29b4085d93ef32270379b09e49118380b0376309bca74fd719d0
arthur#a:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b35a5397ea2d service/example:latest bash -c './start-ser 7 seconds ago Up 7 seconds cranky_wright
later we can attach and check on the service by looking in it's log file:
arthur#a:~$ docker attach b35a5397ea2d
root#b35a5397ea2d:/# cat service.log
service is running
service is running
service is running
root#b35a5397ea2d:/#
I don't recommend running sshd inside the container because it leaves an option for attackers that isn't strictly useful for me.
A lots of questions in there. I would firstly suggest you go through the docker tutorial to grasp some of the underlying concepts. That said...
That Dockerfile will never run in the background, that's not how docker works. There is no cmd, no entrypoint, nothing to run.
Docker by default runs one task, when that returns the container stops. So if all you wanted was a sshd you would run that as your CMD in non daemon mode. (sshd -D)
There are ways to run daemonized apps though:
Using supervisord, as documented on the docker site.
Another alternative is phusion/baseimage.
Phusion/baseimage provides ssh access, but honestly to do what I need in containers I find nsenter easier to use. Especially when paired with the phusion docker-bash tool.
Notice: this answer promotes a tool I've written.
First of all, conceptually running multiple processes in one container is not the right approach (https://docs.docker.com/articles/dockerfile_best-practices/). A more favorable solution is one that involves multiple containers each running their own process/service. Linking them together would result in a coherent application.
I've created a containerized SSH server that you can 'stick' to any running container. This way you can create compositions with every container, without that container even knowing about ssh. The only requirement is that the container has bash.
The following example would start an SSH server attached to a container with name 'sshd-web-server1'.
docker run -ti --name sshd-web-server1 -e CONTAINER=web-server1 -p 2222:22 \
-v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker \
jeroenpeeters/docker-ssh
You connect to the SSH server with your ssh client of choice, just as you normally would.
Be adviced: Docker-SSH is currently still under development, but it does work! Please let me know what you think
For more pointers and documentation see: https://github.com/jeroenpeeters/docker-ssh

Killing a Process in a Running Docker Container

I have a server-side application running in a Docker container. One of the processes in it has hung and needs to be killed (the application will then spawn another process to replace it).
Is there any way to kill that process without stopping the Docker container?
It is not possible with Docker for now, but seems to be scheduled for 0.8, see issue #1228 here.
It is however possible to use lxc-attach to run a shell in an existing container (seen in the above issue comments) and you then can kill your hung process from there :
$ lxc-attach -n FULLCONTAINERID /bin/bash
You can get the FULLCONTAINERID with docker ps --no-trunc=true :
root#turmes /home/zoobab [35]# docker ps --no-trunc=true
CONTAINER ID IMAGE > COMMAND C STATUS PORTS NAMES
2741d88a51148e66d7b2b44d8c1cc6ed7d1515f370be5d00bd003d40cf8d575b zoobab/centos57:latest kamailio -P /var/run/kamailio.pid -m 64 -M 4 -u kamailio -g kamailio -D 1 Up 19 minutes angry_fermat
root#turmes /home/zoobab [36]#
If running Docker 1.3 or newer is not an option, you can still obtain access to a root shell inside the Docker Container using nsenter.
This blog post has all the instructions you need.
Once you have root shell access, you can of course perform any operation you like.
maybe times have changed but as of docker.latest:
docker kill 593690fe0087 killed the CONTAINER ID when I ran docker ps. I had a container there for 2 weeks and only saw it now when the environment wasn't up.
You can do this now in Docker 1.3 using the exec command:
docker exec container_name kill process_name

Resources