How to load apparmor custom profile from docker host to ubuntu container?

Viewed 110

I want to load the custom app armor profile which i have loaded in docker host to inside the ubuntu docker container.When i try to run the below command and check the apparmor_status i'm getting the below error

docker run -d --privileged --security-opt "apparmor=docker-nginx-sample" -p 80:80 -d --name apparmor-nginx apparmubun sh -c 'sleep infinity'

# docker exec -it c67fb9a526ad sh
# 
# 
# apparmor_status
apparmor module is loaded.
apparmor filesystem is not mounted.

So i tried to restart the apparmor service in the docker command option while running docker run as below

docker run -d --privileged  -v /sys:/sys:ro --security-opt="apparmor:docker-nginx-sample" -p 80:80 --name=apparmor apparmubun sh -c 'service apparmor restart;apparmor_status;sleep infinity'

Getting the below error

docker logs b8611278d34e
/etc/init.d/apparmor: 428: /lib/lsb/init-functions: cannot create /dev/null: Permission denied
Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)
Warning: unable to find a suitable fs in /proc/mounts, is it mounted?
Use --subdomainfs to override.
Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)
Warning: unable to find a suitable fs in /proc/mounts, is it mounted?
Use --subdomainfs to override.
Cache read/write disabled: interface file missing. (Kernel needs AppArmor 2.4 compatibility patch.)
Warning: unable to find a suitable fs in /proc/mounts, is it mounted?
Use --subdomainfs to override.

BUt if i try after to execute the service restart command after created the container than its working fine

~# docker exec -it 01b6bdf72586 sh -c 'service apparmor restart;apparmor_status'
 * Restarting AppArmor                                                                                                                                                                                       * Reloading AppArmor profiles...                                                                                                                                                                    [ OK ] 
                                                                                                                                                                                                     [ OK ]
apparmor module is loaded.
44 profiles are loaded.
25 profiles are in enforce mode.

Could you please help me how to do this while running docker run command itself

Thanks in advance

0 Answers
Related