docker on ubuntu 16.04 error when killing container
AppArmor (Application Armor) is a Linux security module that protects an operating system and its applications from security threats. To use it, a system administrator associates an AppArmor security profile with each program. Docker expects to find an AppArmor policy loaded and enforced. Check default profiles with:
# sudo apparmor_status
To use docker default profile on a container, run:
$ docker run --rm -it --name test-container --security-opt apparmor=docker-default image-name
You disable it using the commands:
--security-opt apparmor=unconfined
With the docker run commands.
To disable apparmor service, use:
# systemctl stop apparmor && systemctl disable apparmor
For Ubuntu 14. Use:
# service apparmor stop
# update-rc.d -f apparmor remove
It’s recommended to set working profiles for Docker apparmor than disabling it, especially for production setups.
Check this awesome google document on Securing Containers with AppArmor.
https://cloud.google.com/container-optimized-os/docs/how-to/secure-apparmor
Cannot kill container: container-id : tried to kill container, but did not receive an exit event
I used wilon's answer from https://forums.docker.com/t/restart-docker-from-command-line/9420/2
I ran killall Docker && open /Applications/Docker.app
Once that was done, I ran docker-compose down
and all containers stopped as expected.
Error response from daemon: cannot stop container - signaling init process caused permission denied
I'm going to disagree with everyone suggesting sudo. The docker command sends api calls to the daemon, and if you needed sudo to run the command, you would know from the failure to connect to the docker socket. The daemon itself should be running as root.
The permission error to me looks like something that could be caused by an AppArmor policy or it could just be a bug in the engine/containerd/runc. You are also running Ubuntu 18.04 which docker only recently added support, so if possible, try running a slightly older version of Ubuntu LTS, or see if one of the edge/nightly builds fixes the issue. In the short term, you may have luck restarting the docker engine (systemctl restart docker
) and possibly the entire host to see if that clears up the issue.
How to stop running Container, if error response from daemon is: Cannot Kill Container [...] permission denied?
I solved it but I am not sure why. I think I solved it by restarting the VM and restart docker with these commands
Flush changes: $ sudo systemctl daemon-reload
Restart Docker: $ sudo systemctl restart docker
docker compose down fails due to permission denied
I was able to work around the problem by running:
sudo killall docker-containerd-shim
And then docker-compose down
started working for me.
I found the solution in this bug report, and it seems that it involves a backport of a fix to the runc code.
EDIT
It seems that the root cause of these problems on my system was the Docker snap image on my Ubuntu 18.04 installation. I completely removed the snap image and reinstalled Docker using https://get.docker.io, and I no longer encounter these problems. In the meantime, the rest of my answer above worked for me as a workaround.
Related Topics
How to Access the Base Filename of a File You Are Sourcing in Bash
Setting the Thread /Proc/Pid/Cmdline
Making 'Long' 4 Bytes in Gcc on a 64-Bit Linux MAChine
Setting Up Jenkins Slave on MAC Os
How to Initialize the Attribute Group Correctly for a Platform Driver
Syntax Error: Operand Expected When Using Bash
How to Build an If Condition in Shell to Check Whether Curl Succeeded
Linux Diff Get Only Line Number in the Output
Converting a Pcap Trace to Netflow Format
How to Store Linux Command Output into a Variable in Puppet
Replace Text Based on a Dictionary
Initiating Dynamic Variables (Variable Variables) in Bash Shell Script
Windows Equivalent of ./ (Current Directory)
Compile Linux Kernel (2.6) Module Including Non Kernel Headers