TGIMBA TypeScript API Tuneup – Step 5 – Local Dynamo Db in Docker Container

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>

 Screen Shot 2018-01-02 at 3.16.59 PM

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.

Screen Shot 2018-01-03 at 10.26.48 PM

  • 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.

Screen Shot 2018-01-03 at 10.40.42 PM

  • browser – localhost:8000/shell

Screen Shot 2018-01-03 at 10.26.28 PM

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.

Stay tuned!

References

  1. https://docs.docker.com/get-started/
  2. https://www.youtube.com/watch?v=JBODRMslzAU
  3. https://www.youtube.com/watch?v=hnxI-K10auY
  4. https://github.com/trayio/dynamodb-local/blob/master/Dockerfile
  5. https://github.com/owi1972/dynamodb-local
  6. https://gist.github.com/JeffBelback/5687bb02f3618965ca8f
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s