In this blog post, I will take the next step and put the local Dynamo Db instance into a docker container I can use. Prior to this, I was launching it from the command line each time I wanted to use it. The SQL Server instance is already contained in a container.
The first step in this is to understand how to create a docker container. I found an excellent resource (reference #3) that walks you through the very basics. When learning something new, I prefer to start with a hello world version of whatever technology I am learning. The steps below are from that tutorial. Specifically:
- terminal – touch Dockerfile
- Open up created docker file (I used sublime) and put in these commands
- FROM alpine
- CMD [“echo”, “hello world!”]
- terminal – docker build .
- terminal – docker run –name test 26bd8e1351ee
- “hello world!” is printed to screen
NOTE: On this tutorial, there was initially an error with the commands. So, he had to run the command ‘docker rm test’ to remove the previous container until the new updated one could be run.
- Adding an external script file
- terminal – touch script.sh
- Put into file
- #! /bin/sh
- echo Hello from a script file
- top (return list of processes inside docker)
- terminal – chmod +x script.sh
- terminal – docker build .
- terminal – docker rm test
- terminal – docker run –name test <image id created from build statement>
Now that we have the basics on how to handle simple docker containers, let’s see if we can build one for the docker image. When I looked up what was available, there were already some existing containers running the local Dynamo Db instance. The one I chose to use (see reference #5 which is a fork of reference #4) was the simplest one I found. Specifically:
- Create a Dockerfile (exact name) that looks like this.
- terminal (inside the same directory as Dockerfile) – docker build .
- terminal – docker run -p 8000:8000 –name test <container id from above statement>
- NOTE: 8000:8000 seems required to allow that port to access the shell.
- browser – localhost:8000/shell
One error I encountered was a self signed certificate issue when using another container that the curl command used http. The quickest work around I found was to use -k on the curl statement that downloads the Dynamo Db Jar:
RUN /usr/bin/curl -L -k http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest | /bin/tar xz
However, the last container I found used https, so this was no longer an issue.
If you find yourself with a really long list of docker containers and images, checkout reference #6 for how to quickly clean them up. The commands from the reference should be executed in this order:
- docker stop $(docker ps -a -q)
- docker rm $(docker ps -a -q)
- docker rmi $(docker images -q)
Next will be incorporating these containers inside the TGIMBA Node JS AWS Code Pipeline.