Search code examples
dockermacosaws-samaws-sam-cli

AWS sam build failed due to docker not running in macOS (BUT it is running)


What I'm trying to do

To try out the AWS SAM (Serverless Application Model) to deploy ML model. I used their sam machine learning template with PyTorch. This template utilized Docker, which is the root of the problem. Unfortunately, Docker is necessary for my use case since it's the only way to deploy large repo (PyTorch module is large).

The Problem

When I run the command sam build to build the application, I got the error:

Build Failed
Error: Building image for InferenceFunction requires Docker. is Docker running?

However, the Docker desktop that I installed is running just fine.

enter image description here Docker is running and I can also run docker run hello-world to validate that I can run Docker properly.

To Reproduce the issue

  1. Create SAM repo

    sam init
    
  2. Select AWS Quick Start Templates to choose a starting template. (Choice: 1)

  3. Choose the Machine Learning template. (Template: 13)

  4. Select python3.9 as runtime (Runtime: 1). Actually, this doesn't matter as I've tried python3.8 and 3.10 as well.

  5. Select PyTorch Machine Learning Inference API as starter template. (Template: 1)

  6. Opt out for X-Ray and CloudWatch Application Insights. Again, these don't matter.

  7. Set the project name as you like.

  8. cd into the project folder and then build the application (**Make sure you have docker running)

    sam build
    

Hopefully the same error will occur.

My Spec:

  • Macbook Air M2. (Not sure if this issue only occurs for Apple Silicon chip or not)

  • Docker Desktop 4.18.0 (104112)

  • SAM CLI, version 1.78.0

I haven't found any stackoverflow posts that encounter the same problem, only the similar ones. For example:

AWS Lambda Sam can't find docker

The accepted solution is about user group but I think it's for Linux, since from what I read, Mac shouldn't have this issue.

I suspect that it's about AWS SAM cannot find my Docker.


Solution

  • I've finally solved my own issue. Apparently, it seems like the root cause is Docker version 4.18.0. Either there's a bug in this version or the version is too new for SAM. I installed the older version (4.15.0) and it worked.