title: AWS SAM CLI in Docker container results in ClassNotFoundException
body: <p>I'm trying to make AWS SAM CLI part of my docker-compose file, based on <a href="https://github.com/cnadiminti/docker-aws-sam-local" rel="nofollow noreferrer">this project</a>. Everything seems to come up appropriately, except when I invoke my Lambda function I get a ClassNotFoundException. I've seen several people have problems with permissions that manifest similarly, but even when I make all the files 777 there's no change. I can also see in the logs that it's decompressing the right jar file, and I've decompressed the file myself and seen the class it "can't find".</p>
  
  <p>This is my Docker file:</p>
  
  <pre><code>FROM alpine:3.8
  
  RUN apk add --no-cache python3 python3-dev gcc musl-dev &amp;&amp; \
      python3 -m ensurepip &amp;&amp; \
      rm -r /usr/lib/python*/ensurepip &amp;&amp; \
      pip3 install --upgrade pip setuptools &amp;&amp; \
      if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi &amp;&amp; \
      if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi &amp;&amp; \
      rm -r /root/.cache
  
  ENV PATH $PATH:/root/.local/bin
  
  RUN pip3 install --user awscli
  RUN pip3 install --user aws-sam-cli
  
  COPY conf/lambda /var/opt/lambda
  COPY lib/lambda.jar /var/opt/lambda/lambda.jar
  RUN chmod -R 0777 /var/opt/lambda
  
  RUN python -m site --user-base
  
  WORKDIR /var/opt/lambda
  </code></pre>
  
  <p>And the relevant portion of docker-compose.yml:</p>
  
  <pre><code>sam:
      build:
        context: .
        dockerfile: Dockerfile-sam
      networks:
        - sam-local
      command: sam local invoke StartPiSessionFunction -e event.json --template template.yaml
      hostname: sam
      expose:
        - 3000
      ports:
        - 3000:3000
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock
  </code></pre>
  
  <p>SAM template:</p>
  
  <pre><code>AWSTemplate
  FormatVersion: '2010-09-09'
  Transform: 'AWS::Serverless-2016-10-31'
  Resources:
    StartPiSessionFunction:
      Type: 'AWS::Serverless::Function'
      Properties:
        Runtime: java8
        Handler: com.company.StartPiSession
        Timeout: 60
        CodeUri: lambda.jar
  </code></pre>
  
  <p>And my output logs:</p>
  
  <pre><code>2018-08-10 15:32:41 Invoking com.company.StartPiSession (java8)
  2018-08-10 15:32:41 Starting new HTTP connection (1): 169.254.169.254
  2018-08-10 15:32:42 Decompressing /var/opt/lambda/lambda.jar
  
  Fetching lambci/lambda:java8 Docker container image......
  2018-08-10 15:33:18 Mounting /tmp/tmpsth810ki as /var/task:ro inside runtime container
  START RequestId: eb907a6f-68c3-4afe-90b7-87a73a957322 Version: $LATEST
  java.lang.ClassNotFoundException: com.company.StartPiSession
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:348)
  
  END RequestId: eb907a6f-68c3-4afe-90b7-87a73a957322
  REPORT RequestId: eb907a6f-68c3-4afe-90b7-87a73a957322  Duration: 3.84 ms   Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 3 MB   
  </code></pre>