Closed ffMathy closed 11 months ago
error while creating mount source path
'/host_mnt/workspace/hello-world': mkdir /host_mnt/workspace: read-only file system")
Seems to be the culprit. Digging deeper to understand, Is this about trying to do docker in docker?
Well, essentially we just want to use the SAM CLI in a devcontainer in some way.
But no matter what we do, it (the SAM CLI or the devcontainer or vscode) crashes/disconnects in some weird manner, one or the other way.
We find it almost impossible to use, and we've spent many weeks of trying out many different options.
I think it's really important that this becomes officially supported and well-tested by the SAM team. Perhaps even documented with an example.
I forgot to mention that to repro, you must:
Hi, thanks for specifying the reproducing steps, I was able to run sam local start-api in the dev container using the repo you provided in scenario 2, however I had no issues starting it and invoking it. I also made sure that it was my local files that were edited by verifying changes on them when re starting and invoking. Could you let me know more about how you reproduced it on scenario 2 and more specifically attach the output of sam --info inside the dev container? I have some theories on what may have happened but I need more information about reproducing it to verify them. Thanks
Scenario 2 only fails on Mac. Scenario 1 only fails on Windows when Docker is used via WSL2.
Did you use the right OS?
We verified with 2 Windows machines and 2 Mac machines.
Also note that the repro link to scenario 1 and 2 are not the same. They are linking to two separate branches.
I have verified using the correct scenario 2 link, I can still run my local server fine with ./start.sh. Just to verify you are failing at that script and not running execute.sh right? Also can you please send the sam --info regardless for the dev container, I am still having issues reproducing it
I see. I'll provide the SAM information soon when I'm at my computer.
Start.sh is not enough 🙂 You need to also execute. It's only once it executes that the container disconnects.
Here is my sam --info
output. I ran it inside the dev-container on my Mac machine:
{
"version": "1.97.0",
"system": {
"python": "3.11.2",
"os": "Linux-5.15.49-linuxkit-pr-aarch64-with-glibc2.36"
},
"additional_dependencies": {
"docker_engine": "24.0.5",
"aws_cdk": "Not available",
"terraform": "Not available"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}
My Mac is an M1 Mac by the way, so ARM architecture. Not sure if it matters.
Hi, our team is still having issues reproducing your error on scenario 2 with the windows_fix, host_mnt/workspace is interesting because it is not part of our codebase of all in creating new paths like this. This combined with the fact that we cant replicate it with the same environment points it towards being an issue with docker. A couple google searches from similar issues indicate that it may be a problem with not downloading and updating docker through the official supported sources (https://github.com/moby/moby/issues/34427 and https://stackoverflow.com/questions/45764477/docker-compose-error-while-creating-mount-source-path). Could you try uninstalling re installing docker through the official areas and let us know what happens then? How is docker installed on your machine?
I'll investigate tomorrow.
As for scenario 1 on Mac, is that possible to replicate for you?
Scenario 1 on Mac works properly for me, for windows I will get back to you on this, having some issues with my virtual machine for now
Ah yes I meant scenario 1 on Windows.
Sounds good!
For Windows, Docker in docker is not working properly for me, as in Docker is not installed in the dev container so I can not verify any of the scenarios on the window machine. Was docker set up correctly for you on your windows machine inside the dev container?
So docker was setup on the windows machine itself, and exposed through WSL2.
In the mac branch, the container connection was somehow broken, while in the windows branch it was fine.
Docker itself was setup correctly, as other contains that were not using sam cli are working fine
Great, did the response on scenario 2 for mac change after fixing docker?
Hey, just pinging to inquire about an update if you have a fix for both of the scenarios after updating the docker. If so, I can close the ticket :).
Hey, just pinging to inquire about an update if you have a fix for both of the scenarios after updating the docker. If so, I can close the ticket :).
We will get back with a response tomorrow. Please don't close yet.
Cc @stefanalexandru02 🙏
No, it's still failing with the latest docker version. Same exact devcontainer crash on Windows
Hi, sorry about the delay in response. I can reproduce this issue inside of WSL2 (instead of on Windows). We'll need to investigate a bit deeper as to why this happens on Windows, and why the provided fix works on one OS an not the other before we can provide a definitive fix.
This the provided project works in Windows though (not WSL2), so this could be a potential workaround for now while we investigate.
I did some investigating here and came to a similar conclusion to @lucashuy.
On Mac, I was able to run commands successfully both with binding the host socket and without. Without the bind it worked out-of-the-box. With the bind, I had to update the file sharing settings on the host machine that were adopted by the dev container.
On Windows, I am able to get SAM CLI working on the dev container when starting VS Code from Windows itself, not WSL. With WSL, I am seeing the same issue being reported. My question is why use WSL as an intermediary here? It seems to me as though the end goal of using the dev container is the same whether using Windows or WSL.
Is there a use-case we're missing that requires you to run dev container with WSL? If not, I think we can resolve this issue.
Main reason is performance. When running docker using WSL backend, it's much slower starting it from Windows compared to WSL, especially for larger projects.
Yes, and WSL is also default for everyone. It's what most people use nowadays.
Did some more digging today, and we were able to get it to work with WSL. There were a few issues that we needed to resolve:
CodeUri
property should match the path corresponding to the WSL filesystem, not the dev container filesystem."remoteUser": "root",
in the .devcontainer.json
, this causes an issue with sam build
since it will create an .aws-sam
directory owned by root, and subsequent commands won't have sufficient permissions. You can either update the user (recommended) or change the permissions of the .aws-sam
directory after build.~/.docker/config
and then login to Docker with docker login
.--container-host host.docker.internal
flag like you have in your example.There are a lot of levels of virtualization here that complicate things so let us know if these steps help!
Thank you for looking into it. Have not yet verified that.
It would be great if there were some documentation on an approach to SAM in WSL, that was verified working on WSL + Mac. It's a maze right now, and it's really hard to get working for both at the same time.
We can look into adding some more documentation about development environments and some of the nuances with WSL and dev container.
I am going to remove the bug
tag since this is a system configuration issue and nothing we can really do on the SAM CLI side.
Resolving for now. Please create a new issue if anything else comes up!
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
I must say I am quite disappointed in this. Wouldn't currently recommend the SAM CLI to anyone in its current state. I hope things will improve.
3. I'm not entirely sure why, but Docker kept asking for credentials. I needed to remove the existing credential store config located in `~/.docker/config` and then login to Docker with `docker login`.
This resolved my issue. Thanks heaps for your investigation, @mildaniel !
So just to confirm. WSL + DevContainer + sam local start-lambda
working here.
Description:
When I want to run
sam local start-api
inside a DevContainer, I encounter different failures depending on what platform my host machine is in, and what configuration I have.Steps to reproduce:
There are two variants (or scenarios) of configurations I can make. One that fails consistently on Windows, and one that fails consistently on Mac. But I can never have it not fail on both.
Scenario 1
Repro: https://github.com/ffMathy/aws-sam-cli-repro/tree/main (
main
branch)Scenario 2
Repro: https://github.com/ffMathy/aws-sam-cli-repro/tree/windows_fix (
windows_fix
branch)Diff from Scenario 1: https://github.com/ffMathy/aws-sam-cli-repro/compare/main...windows_fix
Error: Lambda functions containers initialization failed
.Observed result:
Scenario 1 failure (Windows)
Scenario 2 failure (Mac)
Expected result:
I expected the SAM CLI to be launchable from inside Docker. Docker is heavily used for most developers, especially dev-containers.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: SAM CLI, version 1.97.0