How to create Dockerfile,Docker Image,Docker Container & access application from container

 docker notes(21.12.2025 Sunday)
=========================
step1: create Linux server
       add port number 4000 for your server
       or create security group directly 
       and add security group for your server
step2: login Linux server
step3: create a directory 
step4: create index.html file inside this directory 
name: vansro (folder name)
      a).create index.html file
        copy the code
      
      b).create Dockerfile
         nano Dockerfile
         FROM nginx
         COPY index.html /usr/share/nginx/html
      
         save and close the file(ctrl+o press enter ctrl+x)
step6: Install Docker software
step7: start the docker service
step8: create docker image
       how to create docker image from the Dockerfile ?
       command: docker build
       docker build -t kkapp1
       
       you can create image 
       and the image name is : kkapp1

step9:check docker images
how can I check all my images
---------------------------------
docker images
it displays all the available images
 
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
kkapp1                latest    1194d7244ec6   3 minutes ago   152MB
image name:kkapp1

step10:create & start docker container
 
how to create docker container by using docker image ?
command: docker run
docker run is a command which is used to create and start container 

docker run -p 4000:80 kkapp1
docker run -d -p 4000:80 kkapp1

docker run
---------
create container and start container

"-d"
----
detached mode represents "d"
background mode
detach mode (d)
detached mode
RUN THE CONTAINER IN DETACHED MODE or in the background mode

4000:80
--------
host machine port number : container port number
docker forward the request to container through port 80
where our actual application is available or running 
step11:check the containers
how can I check all my containers
---------------------------------
docker ps
it displays all the containers 
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                  673155e558a3     kkapp1    "/docker-entrypoint.…"   2 minutes ago   Up 2 minutes   
container ID = 12 characters ( numbers AND characters)
image ID = 12 characters ( numbers AND characters)

step12:check the container port number
how can you check your container port 
=====================================
docker port 
docker port is a command 
which is used to displays the container port number
syntax: docker port <container ID>

step13: access application
how can I access my application:
--------------------------------
open browser and type 
server IP address: port number
1.2.3.4:4000
you can see your application which is running in your container
--end --

Comments

Popular posts from this blog

Kubernetes cluster setup NOTES step by step using minikube

Top 10 Git Commands

SonarQube Installation & Configuration Step by step