Windows 7环境下用Docker创建AWS Lambda Layer遇文件找不到错误求助
Hey there, sorry you've been stuck on this all day—let's break this down step by step to get it working.
First, Fix the Command Syntax Issue
You combined the cd and docker run commands in one line without a proper separator, which means the cd command never actually runs. Docker tries to look for requirements.txt in its default working directory instead of your mylayer folder, hence the "No such file or directory" error.
Correct the command by splitting them with && to ensure the directory change happens before running Docker:
cd /c/Users/Myname/mylayer && docker run -v "$PWD":/var/task lambci/lambda:build-python3.8 /bin/sh -c "pip install -r requirements.txt -t python/lib/python3.8/site-packages/; exit"
Second, Account for Docker Toolbox Path Differences
Docker Toolbox on Windows 7 uses a VirtualBox virtual machine, which maps your Windows C:\Users directory to /c/Users inside the VM. You'll need to use Linux-style paths (forward slashes, case-sensitive) instead of Windows-style paths here.
For extra reliability, you can skip $PWD entirely and use an absolute path for the volume mount—this avoids any path resolution quirks in the Docker Toolbox terminal:
docker run -v "/c/Users/Myname/mylayer":/var/task lambci/lambda:build-python3.8 /bin/sh -c "pip install -r requirements.txt -t python/lib/python3.8/site-packages/; exit"
Third, Verify Your File & Folder Structure
Before re-running the command, double-check that your setup is correct:
- In the Docker Toolbox terminal, run this to confirm your files exist in the mapped directory:
You should seecd /c/Users/Myname/mylayer && lsrequirements.txtand yourpython/lib/python3.8/site-packages/directory listed here. - If you don't see the files, make sure
requirements.txtis actually saved inC:\Users\Myname\mylayeron your Windows machine. - If the directory structure is missing, re-create
python/lib/python3.8/site-packages/exactly as required—Docker needs this target folder to install dependencies into.
Troubleshooting Bonus: Enter the Container Interactively
If you're still stuck, run this command to enter the Docker container directly and inspect the files:
docker run -it -v "/c/Users/Myname/mylayer":/var/task lambci/lambda:build-python3.8 /bin/sh
Once inside, run ls /var/task to check if requirements.txt is present. If it's not, your volume mount path is incorrect—double-check the Windows-to-VM path mapping.
内容的提问来源于stack exchange,提问作者Alex M

