DEV Community

Cover image for Install Docker using command line and pull code from github
Dhaval Upadhyay
Dhaval Upadhyay

Posted on

19 2 1 1 1

Install Docker using command line and pull code from github

Introduction

  • Briefly introduce the importance of CI/CD in modern application development.
  • Highlight the benefits of deploying Node.js Docker applications using aws command line and GitHub Actions.
  • Outline the steps that will be covered in the blog.

Prerequisites

  • aws account.
  • GitHub repository with your Node.js application.
  • Basic knowledge of Docker and GitHub Actions.

Follow Below steps to install docker first

1. update the package list

sudo apt update
sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

2. Install prerequisite packages

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

Enter fullscreen mode Exit fullscreen mode

3. Add Docker's official GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Enter fullscreen mode Exit fullscreen mode

4. Set up the Docker stable repository

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Enter fullscreen mode Exit fullscreen mode

5. Install Docker

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io

Enter fullscreen mode Exit fullscreen mode

6. Verify Docker installation

docker --version

Enter fullscreen mode Exit fullscreen mode

7. Verify Docker installation

docker --version

Enter fullscreen mode Exit fullscreen mode

Install Docker Compose

1. Download and install Docker Compose

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

2. Set executable permissions

sudo chmod +x /usr/local/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

3. Verify installation

docker-compose --version
Enter fullscreen mode Exit fullscreen mode

Clone Your Node.js Project from GitHub

1. Install Git

sudo apt install -y git
Enter fullscreen mode Exit fullscreen mode

2. Clone the repository

git clone "git_url"
cd "repo_name"
Enter fullscreen mode Exit fullscreen mode

Create Dockerfile for Node.js Application

1. Inside the project directory, create a Dockerfile

# Use Node.js base image
FROM node:16-alpine

# Set working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy application code
COPY . .

# Expose the application port (e.g., 3000)
EXPOSE 3000

# Start the application
CMD ["npm", "start"]

Enter fullscreen mode Exit fullscreen mode

Build and Run Docker Container

1. Build the Docker image

docker-compose build (if you have docker-compose.yml)

docker run -d -p 3000:3000 --name node_structure node:20 tail -f /dev/null  
(if you do not have docker-compose.yml)
Enter fullscreen mode Exit fullscreen mode

2. Run the container

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

3. Verify running container

docker ps
Enter fullscreen mode Exit fullscreen mode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (8)

Collapse
 
bnystrom profile image
Bryan Nystrom

Also, docker-compose is (being) depricated in favor to the compose plugin.
Commands should be "docker compose..." not "docker-compose" with the plugin.

Otherwise, useful information for anyone who needs to add docker and git on a fresh linux install.

Collapse
 
dhaval_upadhyay_30f8292a8 profile image
Dhaval Upadhyay

thanks for clarification

Collapse
 
tbroyer profile image
Thomas Broyer

Why don't you install Compose from the packages as well? (apt install docker-compose-plugin)

Collapse
 
dhaval_upadhyay_30f8292a8 profile image
Dhaval Upadhyay • Edited

*You can refer below link for upload code using ci/cd pipeline of github actions
*

upload code using ci/cd pipeline of github actions

Collapse
 
nadeem_zia_257af7e986ffc6 profile image
nadeem zia

Was worth reading, thanks for information

Collapse
 
dhaval_upadhyay_30f8292a8 profile image
Dhaval Upadhyay

thanks

Collapse
 
ilyas_08 profile image
Ettourach

hey I m Ilyas from Morocco can someone explain how to get my GitHub repository Node.js application to start install docker

Collapse
 
dhaval_upadhyay_30f8292a8 profile image
Dhaval Upadhyay

you can create new empty repository in github and then upload node js code to that repo

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay