Cannot delete files on docker host

I’m using the following shell script to extract my databases in the entrypoint and startup the container.

if [ ! -d "/var/lib/mysql/assetmanager" ]; then
tar -zxvf mysql.tar.gz
exec /usr/bin/mysqld_safe

On startup I mount a local directory to the /var/lib/mysql directory with the -v parameter and extract then the files with the above script.
But now I can’t delete the extracted files on my host, because permission denied error.
Can someone help me with this problem.

  • Is it possible to add flags by default to Docker run
  • Logging PHP API Request Info from Docker container
  • How to do --rm and --restart in dockerfile?
  • What is the essential difference between docker and rkt?
  • Docker container with status “Dead” after consul healthcheck runs
  • Docker commands via php shell_exec
  • Thx

  • How to send http request from Docker to localhost or Virtual Machine
  • golang project can't find dependencies when run inside a docker container
  • Can't kill supervisord inside of docker container
  • How do I run shell commands from myApp(python) container in myData(mongodb) container?
  • docker-machine inside Symfony Process
  • Cannot pipe docker pid to bash command
  • One Solution collect form web for “Cannot delete files on docker host”

    You cannot delete them because by default process in container executed by root user and extracted files belong to root. if you don’t need these files in mapped dir, use different location for it -v …:/myassets and in script:

    if [ ! -d "/var/lib/mysql/assetmanager" ]; then
    tar -zxvf /myassets/mysql.tar.gz

    you also could map a single file instead of whole directory if you need only that file.

    There are many other solutions, depends what you need:

    • you could delete these files as root: sudo rm …
    • you could delete them in container before exit
    • you could create user in container and create files from this user
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.