Logo

dev-resources.site

for different kinds of informations.

Easy Dockerization with Docker INIT

Published at
9/7/2023
Categories
docker
containers
microservices
dockercompose
Author
pradumnasaraf
Author
13 person written this
pradumnasaraf
open
Easy Dockerization with Docker INIT

Docker Init is changing the game in how we Dockerize our applications.

With docker init, we can quickly generate the Dockerfile, compose.yml, and .dockerignore. In the past, we manually created these files and implemented the best practices.

Now, with just one command and by answering a series of prompts, Docker automatically sets up these necessary files for us. Notably, this new approach ensures that industry best practices are followed.

In today's article, we'll also see a demo of dockerizing a Node application with Docker init.

Prerequisites:

  • Docker Desktop 4.18 or later

Steps:

1) Initialize the Project and Install Dependencies:

For this demonstration, we'll set up a basic application using Node and Express. Begin by initializing your project:



npm init


Enter fullscreen mode Exit fullscreen mode

Then install the Express dependency:



npm i express


Enter fullscreen mode Exit fullscreen mode

2) Add a Start Script:

Add a start script to your package.json file:



"scripts": {
    "start": "node index.js"
},


Enter fullscreen mode Exit fullscreen mode

3) Create a Simple API:

Create an index.js file and insert the following code:



const express = require("express");
const app = express();
const port = 3000;

app.get("/", (req, res) => {
  res.send("Hello World!");
});

app.listen(port, () => {
  console.log(`App listening on port ${port}`);
});


Enter fullscreen mode Exit fullscreen mode

4) Docker INIT:

Run the docker init command and select the language of your project. You'll then be prompted with a series of questions tailored to your project and its structure.

Image description

5) Running the App:

After the setup, execute the command docker compose up --build to construct the images and launch the application.

Terminal Screenshot

That's it. I hope you learned something from this. As the world moves towards containerizing applications, this can be instrumental in accelerating tasks and transitioning from monoliths to microservices.

dockercompose Article's
30 articles in total
Favicon
Want to Learn Docker in Advance Way?
Favicon
deploy Jenkins using docker compose with production ready
Favicon
Docker Advance Part 2: Docker Logging
Favicon
A Simple Guide to Docker Compose & Multi-Container Applications
Favicon
Dockerize nestjs app with postgres
Favicon
Tips and Tricks for Docker Compose: Leveraging the override Feature
Favicon
Dockerize nestjs application with Postgres
Favicon
RabbitMQ container with Docker Compose
Favicon
Quick and simple Local WordPress Setup for Lazy Developers
Favicon
Bug: Docker-compose up?
Favicon
How to resolve Docker Compose Warning WARN[0000] Found orphan containers
Favicon
How to resolve Docker Compose Warning WARN[0000] Found orphan containers
Favicon
How To Set Up Docker SeleniumΒ GRID
Favicon
How to Ensure Docker Compose Uses Environment Variables from the `.env` File
Favicon
Essential Docker Commands for Developers
Favicon
[Docker] How to fix 'host not found in upstream "host.docker.internal"'.
Favicon
Como configurar imagem Docker(PHP e Nginx) para projetos Laravel com PHP 8.3
Favicon
Containerize your multi-services app with docker compose
Favicon
αžŸαž˜αŸ’αžšαžΆαž”αŸ‹αž›αž»αž”αž’αŸ’αžœαžΈαŸ—αž‘αžΆαŸ†αž„ αž’αžŸαŸ‹ αž€αŸ’αž“αž»αž„ Docker compose.
Favicon
Installation of Docker Compose:
Favicon
MongoDB containers with Docker Compose
Favicon
An Overview of Docker Compose and its Features.
Favicon
How to change docker root data directory and why would you want to do that (hint: to optimize space)
Favicon
Containerize a Web Application using docker compose
Favicon
O Docker Compose agora tem uma V2, veja como instalar
Favicon
Vue 2 vite dockerized steps
Favicon
An Advanced Guide (2) to Docker: Managing Multi-Container Applications 🐳
Favicon
How to run mongodb using docker-compose in ubuntu
Favicon
How to run postgres database using docker and docker-compose
Favicon
Easy Dockerization with Docker INIT

Featured ones: