March 30th, 2022

Here’s a Dockerfile I’m using for local cdk development. It installs Docker, CDK and the AWS CLI.

It supports bundling with cdk synth and npm test.

It’s important that your working directory in your container is the same path as it is on your host machine. I check out code to /home/scarab05/sandbox.


 

FROM node:16

RUN apt-get update && apt-get -y install ca-certificates curl gnupg lsb-release 
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update && apt-get -y install docker-ce docker-ce-cli containerd.io && apt-get clean

RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install

RUN npm install -g aws-cdk

USER node
WORKDIR /home/scarab05/sandbox
CMD /bin/bash

 

I build it as follows

docker build -t cdk-build .

I run it as follows

docker run -v /var/run/docker.sock:/var/run/docker.sock \
    -v /home/scarba05/sandbox:/home/scarba05/sandbox \
    -v /tmp:/tmp \
    -it cdk-build /bin/bash