Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error copying file to container using Podman on Windows 11

I'm trying to run a SQL script against a SQL Server instance that is running inside a Podman container on a Windows 11 host.

To do this, I'm attempting to copy the script file to the container using the following command:

podman cp .\baseline.sql mssql-server-1:/tmp/baseline.sql

it returns:

error rewriting "c:....\baseline.sql" to be relative to "/": expected root directory to be an absolute path, got "/"

It seams the paths are ok, because if I change either the source or destination Podman reports correctly the error.

Has anyone encountered a similar issue or can provide insight into what might be going wrong here? Any advice or suggestions would be greatly appreciated.

like image 577
MiguelSlv Avatar asked Nov 18 '25 17:11

MiguelSlv


1 Answers

This is generally followed by containers/podman issue 14862:

In the meantime as a workaround you can access your windows drive through the mount that is on the wsl linux host, using unix path conventions, like this:

podman cp /mnt/c/users/foo/bar/file.bak mycontainer:/var/opt/backups

And:

I was able to get a file copy into my container working with the following.
I redeployed my podman machine, rebuilt my container...
this does work:

wsl -d podman-machine-default -u user enterns podman cp \
    /mnt/d/2022_Projects/assessments/HK197500195.bin se92:/root/

Or:

wsl -d podman-machine-default -u user enterns podman cp \
    /mnt/c/"your file location" container:/sql/

Meaning:

"Prefixing" docker cp with wsl -d podman-machine-default -u user enterns also worked for me. Concretely, I wrote:

wsl -d podman-machine-default -u user enterns podman cp \
    "myfile.txt" my-container-name:/tmp/

Also:

Simple workaround for me is to use podman machine ssh command like this:

podman machine ssh "podman cp /mnt/c/dev/file.py container:/usr/src/app"

Q1 2025: Dominick Gendill add this testimony:

I've been using the wsl copy workaround for a while now, but I've recently upgraded to Podman Desktop v1.15.0 and Podman v5.3.1, and for some reason it's stopped working, and I get the error "Error: container "sql_server_2017" does not exist"

wsl -d podman-machine-default -u user enterns podman cp /mnt/c/Users/dgendill/Documents/file.sql sql_server_2017:/home/file.sql

I'm certain I have the "sql_server_2017" container running because I can see it running in Podman Desktop.

I also tried running podman cp /mnt/c/Users/dgendill/Documents/file.sql sql_server_2017:/home/file.sql and I get a message saying the file doesn't exist, but I'm certain that path exists.

Error: "/mnt/c/Users/dgendill/Documents/file.sql" could not be found on the host: no such file or directory

I was able to get everything working by...

  1. Ran Cleanup / Purge data in Troubleshooting > Repair
  2. Ran podman machine init
  3. Ran podman machine start
  4. Ran podman pull mcr.microsoft.com/mssql/server:2017-latest
  5. Ran podman run -d --name sql_server_2017 ...

Then I was able to run the wsl command in windows CMD.
Running in windows bash didn't work.

like image 125
VonC Avatar answered Nov 20 '25 14:11

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!