2

I have a database that is running locally in a sql docker container, which I want to backup and be able to use as part of a COPY command when creating a custom sql docker image then eventually use it as part of a RESTORE DATABASE command with sqlcmd.

However, when I right click on the DB in SSMS and go to backup I can only seem to backup inside the container, and not locally on my C: drive.

Is there a way I can retrieve the .bak file to my local drive?

user1574598
  • 3,771
  • 7
  • 44
  • 67
  • 1
    Containers are explicitly designed so that they have very limited access to resources outside of the container itself; hence the name (everything is in a container, and the container can only access objects within that container). You could mount the directory that the backups are stored in on the host to the container (see [How to mount a host directory in a Docker container](https://stackoverflow.com/q/23439126/2029983)), however, don't mount `C:`, only the directory you need. Otherwise you'll need to copy the `.bak` file to the container's file system. – Thom A Apr 06 '20 at 11:55
  • 1
    Thanks, so say I save it in the pre-existing folder in the container `/var/backups` then I create a bind mount from there to my local drive, say `C:\mssql\backups`. Sorry I didn't quite understand the last sentence. – user1574598 Apr 06 '20 at 12:15
  • 2
    No, you'll want to create a directory where you want to store the backups on your host machine. Then add that directory as a mount point in the container (personally, i suggest in the `/mnt` directory, but that's preference). Then you can back up to that direoctory in the container, and you'll be able to see it on the host. So, for example, let's say you create the directory `C:\mssql\backups` and mount that in the container in `/mnt/mssql/backups/` when you create the back up in `/mnt/mssql/backups/` you'll be able to see it in `C:\mssql\backups` too. – Thom A Apr 06 '20 at 12:18
  • Ah great, I understand now, and I'll probably use that same naming convention `/mnt` as I have seen it before. I also want to find out how I can use a `.sql` file in conjunction with the `sqlcmd` inside the container, as I would like to put the `RESTORE DATABASE` stuff in there, but that is a separate question to this. – user1574598 Apr 06 '20 at 12:26

0 Answers0