Finding the perfect Docker image to use on your CI can be tough — most stock ones don’t come with all the tools you require and custom ones with the right tools are created and controlled by people you don’t know. Luckily creating your own image is easy and can be done in a few minutes — let’s look at how.
- load and install Docker Desktop if you haven’t already. Links to the apps can be found on their getting started page.
- Create a Docker account — you will need this to upload your image to the Docker Hub.
- Find a suitable starting image — in our case we went with
Note that for now we only need to know the name of the image that we want. The Node image tags can be found on the Node page on Docker Hub.
This image was chosen because it is official and at the time of writing Node 11.9.0 was the latest available version of Node. The Alpine Linux variant was chosen because it is lightweight.
4. Create a file called “Dockerfile” with the following content:
- In your terminal rundocker build . -t your_docker_user/your_image_name
docker build . -t your_docker_user/your_image_name
Your Docker image should build now. The -t is to tag your image — this is how we will reference it later in our CI. After the image has built running docker images should show you a list of images, including the base image and the one we just built.
- Publish the image to Docker Hub by running
docker push your_docker_user/your_image_name
- Make use of the image in your CI 🙌 🎉
For example in Bitbucket Pipelines set the first line of your bitbucket-pipelines.yml file to image: your_docker_user/your_image_name.
Think you’ve got that it takes to join Team SovTech? Get in touch.