-
Couldn't load subscription status.
- Fork 6
Copying files to and from a container
Andrew Pruski edited this page Sep 25, 2020
·
2 revisions
Sometimes we need to pull files out of a container or copy files into one.
This is nice and easy to do in Docker using the docker container cp command.
Let's spin up a container running SQL Server: -
docker container run -d `
-p 15789:1433 `
--env ACCEPT_EULA=Y `
--env MSSQL_SA_PASSWORD=Testing1122 `
--name sqlcontainer1 `
mcr.microsoft.com/mssql/server:2019-CU5-ubuntu-18.04
And we want to copy a backup of a database into that container: -
ls

In order to copy the backup files into the container we run: -
docker container cp testdatabase.bak sqlcontainer1:/var/opt/mssql/data
This copies the backup file testdatabase.bak into the directory /var/opt/mssql/data in the container.
We can check that the backup has been copied in by running: -
docker exec sqlcontainer1 ls -al /var/opt/mssql/data

Now, let's copy that file back out of the container, onto our Docker host: -
docker container cp sqlcontainer1:/var/opt/mssql/data/testdatabase.bak C:\temp

And that's all there is to it!