Giter Site home page Giter Site logo

docker-practice's Introduction

Docker-Practice - Docker Demo

This is a simple Node.js web application built with HTML, CSS, JavaScript, Document Object Model and Express, intended to demonstrate Docker containerization.

Table of Contents

Introduction

docker-practice is a basic Node.js web application that showcases how to containerize a Node.js application using Docker. It provides a simple API built with Express, and the Dockerfile is included to help you understand the steps required to create a Docker image for the application.

Requirements

Before running this Docker demo, ensure you have the following software installed:

  • Docker (Docker Desktop for Windows or macOS, or Docker Engine for Linux)

Docker Installation

Please refer to the official Docker documentation to install Docker on your operating system:

Build Docker Image

Clone this repository to your local machine:

git clone https://github.com/Xolani-M/docker-practice.git 
cd docker-practice

Build the Docker image using the provided Dockerfile:

docker build -t username/your-app:2.0 .
# NOTE: 
      Replace username/your-app:2.0 with the desired name and tag for your Docker image.

Run Docker Container

To run the Docker container from the image, use the following command:

docker run -p 3000:3000 username/your-app:2.0

Access the application in your web browser at http://localhost:3000.

#NOTE: When you run a Docker container with the docker run command, it starts the container in the foreground, and the terminal remains attached to the container process. In this case, you will not be able to execute docker stop directly from the same terminal where the container is running because the terminal is still busy with the container's process. Altinatively you can run the image on DETACHED mode, read further for more info.

Run on Detached Mode (Background) using the -d flag:

docker run -d -p 3000:3000 xomvana022/docker-practice:2.0
  • On detached mode the container runs in the background, and the terminal is free to execute other commands.
  • The docker run command returns immediately with the container ID.
  • You can still view the container's logs using the docker logs <CONTAINER_ID_or_NAME> command.
  • You can stop the container with docker stop <CONTAINER_ID_or_NAME> from the same terminal or any other terminal.

Stop Docker Container

docker ps

which will list the running images in this format

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4e3gg4455235 username/app:2.0 "docker-entrypoint.sā€¦" About a minute ago Up 59 seconds 0.0.0.0:3000->3000/tcp wizardly_almeida

then from there, you want to select the ID or name

  • Using IMAGE ID
docker stop 4e3gg4455235
  • Using NAMES
docker stop wizardly_almeida

Steps To Run The Program

  1. Pull the Docker Image:

    docker pull xomvana022/docker-practice:2.0
  2. Run the Docker Container:

    docker run -p 3000:3000 xomvana022/docker-practice:2.0

You can do the previous steps by:

  1. Using your physical machine.

  2. Or go to play-with-docker to build and run a docker image.

    • Login/Sign In if you have a docker id or Sign Up if you do not have a docker id.
    • click "Start".
    • click "ADD NEW INSTANCE" to create a new virtual machine.

#Tip: - Maximize the terminal by clicking on it and pressing "alt" + "enter"

Contributing

Contributions are welcome! If you find any issues with the Docker demo or have ideas for improvements, please feel free to open an issue or submit a pull request.

docker-practice's People

Contributors

xolani-m avatar

Watchers

 avatar

docker-practice's Issues

Documentation Fix: Tips

On documentation tips you wrote this:

  - To stop the container, press Ctrl + C in the terminal.
  - Or   - To stop the container, press Ctrl + C in the terminal.
  - Or docker stop username/your-app-name

The problems is that you can't stop the docker container with the name you used to create the docker image but you
have to use the running docker image name of the docker ID but if you write username/your-app-name
it will say that it did not find the image
the right way to stop the docker image is to first getting the running container :

docker ps

which will list the running images in this format

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4e3gg4455235 username/app:2.0 "docker-entrypoint.sā€¦" About a minute ago Up 59 seconds 0.0.0.0:3000->3000/tcp wizardly_almeida

then from there, you want to select the ID or name

  • Using IMAGE ID
docker stop 4e3gg4455235
  • Using NAMES
docker stop wizardly_almeida

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.