Creating images

Before we deploy, we need to create an image for our service to run inside. Our service has no dependencies other than the ones defined on the top:

  • express and body-parser: To handle our HTTP requests
  • mysql: It enables us to use a MySQL database
  • sharp: It enables us to manipulate images
  • path: It is a core module to help working with directory paths

The core module is not a problem, and the first three are also not a problem since they're built completely in JavaScript. On the other hand, sharp is compiled, so our image needs to have at least a compiler.

To keep our image as slim as possible, we'll be using the Node.js Alpine version, which is a Node.js image based on Alpine Linux and it has a much smaller size than other distributions. You'll see what I mean in a moment. Let's download the image. Run the following:

docker pull node:alpine

If everything goes well, you should then have a new container image available, as the following screenshot shows:

First, I just checked that we had no local images. Then, I requested that Docker pull the Alpine version of the Node.js official repository. Notice that I didn't specify the version, as I'm targeting the latest stable one. If you want a specific version, head to Docker Hub and search for Node official images.

We now have our image, but there are a couple of things to do before being able to start our microservice. First, we need to create our own image. What we downloaded is just a base image, which doesn't have our code. We need to add our code and dependencies. To do that, we need to create a Dockerfile.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset