Skip to content

An application that demonstrates how to use a CI/CD pipeline to automate the Docker image build process.

Notifications You must be signed in to change notification settings

kusumsiri/docker_Image_expressjs_github_actions

Repository files navigation

Build Docker Images with Github Actions

Introduction

An application that demonstrates how to use a CI/CD pipeline to automate the Docker image build process. This creates an Express.js application image on Docker hub after committing the code to the repository.

In this demonstration, a very simple Express.js file is used as the software source.

Install

If you intend to run the source code before building the docker image, the following commands can be used.

Note: This requires your computer to have a Git client and NodeJS installed.

git clone https://github.com/kusumsiri/ExpressJS_CICD.git
cd ExpressJS_CICD/
npm install
npm start

Then visit http://localhost:3000 to test it.

Building the Docker image

This Dockerfile contains instructions for build the image. It uses the node:current-alpine image as the base. After that it will copy *.json files, install the packages, copy the source code, set the port and finally copy the run command. If you intend to build the docker image locally, the following commands can be used.

Note: This requires your computer to have Docker installed.

docker build -t node-js .

This command will create a docker image and name it as node-js:latest. To check its name run following command.

docker images

Then execute the following command to run the container.

docker run --rm -p 3000:3000 node-js

Then visit http://localhost:3000 to test it.

Note: All these steps must be performed manually when the Docker container needs to be created. But we can automate the process by using a CI/CD pipeline.

CI/CD Pipeline

The main.yml file that handles the CI/CD process. It checkout the source code from GitHub repository, builds the image according to the Dockerfile and finally push the image to docker hub

Now anyone can go to Docker Hub and pull the image and run it easily.

About

An application that demonstrates how to use a CI/CD pipeline to automate the Docker image build process.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages