Professional Documents
Culture Documents
A-: Docker is a software platform that allows you to build, test, and deploy
applications quickly. Docker packages software into
standardized units called containers that have everything the software needs
to run including libraries, system tools, code,
and runtime. Using Docker, you can quickly deploy and scale applications
into any environment and know your code will run.
For Example - If we are making a front-end React application then the image
should contains below mentioned items:
Container Container
Container
App 1 App
2 App 3
Bins/Libs Bins/Libs
Bins/Libs
Node 17 Node 18
Node 19
A container is a standard unit of software that packages up code and all its
dependencies so the application runs quickly
and reliably from one computing environment to another. A Docker container
image is a lightweight, standalone, executable
package of software that includes everything needed to run an application:
code, runtime, system tools, system libraries
and settings.
• Storage, management, and sharing of images with others are made simple via
Docker Hub.
• Docker Hub runs the necessary security checks on our images and generates
a full report on any security flaws.
• Docker Hub can automate the processes like Continuous deployment and
Continuous testing by triggering the Webhooks when the new
image is pushed into Docker Hub.
• With the help of Docker Hub, we can manage the permission for the users,
teams, and organizations.
• We can integrate Docker Hub into our tools like GitHub, Jenkins which
makes workflows easy
• Repositories: It contains the Push and Pull process for container images.
• Teams and Organizations: It allows access to developer/user to private
repositories of container images.
• Docker Official Images: It Pulls and uses high-standard quality container
images rendered by Docker.
• Docker Verified Publisher Images: It Pulls and uses high-standard quality
container images rendered by outside vendors.
• Builds: Automatically build container images from GitHub and Bitbucket and
push them to Docker Hub.
• Webhooks: Trigger actions after a successful push to a repository to
integrate Docker Hub with other services.
• Docker implements a Docker Hub CLI tool that is presently experimental and
an API (Micro-service) that enables you to communicate with
Docker Hub. You can browse the Docker Hub API documentation to explore the
supported endpoints.
Builds Run
Docker File -----> Docker Image -----> Docker Container
|
|
Layer C
Layer B
Layer A
Base Image
09-: Steps to
A-: Following are the steps to ::
• Download Node Image from the docker hub.
• Make a container for node js.
• Run Node js container.
• Write Node js Code inside conatiner.
Note:- Docker file created should not have any file extension.
Step 1: Create a Docker file with tbe name "dockerfile" in the project
directory (note: docker file should not have any extension).
Docker file can be created from terminal using command "touch
dockerfile" or you can create it without command by directly creating inside the
project
directory.
Step 2: Now you have to install Docker in the project. Here we have two
option to do so. First: The moment you create the Docker file
VS code will ask to install Docker with a link. Second: Search
for microsoft extention of the Docker and install it. You can
choose any option to install the Docker.
Step 3: Write the below mentioned code/script into the Docker file created
in Step 1.
FROM baseImage
FROM node: latest
COPY source dest .
COPY . .
RUN command ==========>
RUN npm install
EXPOSE port
EXPOSE 5500
CMD ["executable"]
CMD ["node","index.js"]
Step 4: Execute the code/script created in Step 3 using below command from
terminal.
16-: How to skip any partcular file extention to be added in the docker image
creation?
A-: Just mentioned the extention of the file in the .dockerignore file.
for example: if we want to skip "text' files to be added in the docker image
then just add "*.txt" in the dockerignore file.
19-: Command to delete all docker images and all docker containers.
A-: Command to delete all docker images and all docker containers is:
npm i nodemon
Step 2: Add command under script section in package.json file to run the
application using nodemon like below:
"scripts": {
"test": "react-scripts test",
"eject": "react-scripts eject",
...
...
...,
"dev": "nodemon index.js"
},
24-: Update the script mentioned in Step 3 of point 13 in the docker file to add
the install command for "nodemon"
Now once the docker file is updated we create the docker images and run the
docker container using below command:
Step 1: Create a compose file with tbe name "compose.yaml" in the project
directory directly.
Step 2: Add the below script into the compose file created:
services:
img:
build:
container_name: basic-container
ports:
5500:5500
docker compose up
This command will create the docker image and run the container also.
Step 3: Now create the Docker image in your local machine with the command
Step 4: Login into Docker hub account using below mentioned command:
docker login
Step 5: Push the image to Docker hub repository using below mentioned
command:
Step 3: Now create the Docker image in your local machine with the command
(note: here we have to mention the os name also to identify for which os
we are creating the image
Step 4: Login into Docker hub account using below mentioned command:
docker login
Step 5: Push the image to Docker hub repository using below mentioned
command:
Step 7: Once the new instance is created, then pull the image from the
Docker hub:
Step 8: Now run the Docker image using below mentioned command
You can click on the port no. link displayed on top of the
screen to see your application in the browser.