0

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

#!/bin/bash
if [ ! -d "/var/lib/mysql/assetmanager" ]; then
tar -zxvf mysql.tar.gz
fi
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.

Thx

Flagman
  • 416
  • 6
  • 24

1 Answers1

1

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
fi

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
ISanych
  • 21,590
  • 4
  • 32
  • 52
  • Or they may be owned by the mysql user inside the container. In which case you can either sudo to root to delete them or to the same UID as the mysql user. – Adrian Mouat Jan 12 '15 at 14:36