-->

  • docker-installation-images-containers-port-mapping-guide


    docker-installation-images-containers-port-mapping-guide

     


    Docker is a platform that allows developers and system administrators to package applications and their dependencies into containers. Containers are lightweight, portable and run consistently across different computing environment.



    Docker Learning Path for You



    Week 1

    • Install Docker 
    • Containers vs Images 
    • Pull images 
    • Run containers 
    • Port mapping 



    Week 2 

    • Dockerfile 
    • Build custom images 
    • Environment variables 



    Week 3 


    • Docker Volumes 
    • Docker Networks 
    • Multi-container 
    • applications 



    Week 4 

    • Docker Compose 
    • Deploy React/Node applications 
    • Container troubleshooting 



    But we will start from week 1 module and try to answer the interview level question also 

     

     Install Docker 

     

     For installing the docker via docker-desktop and via wsl linux. you can choose any of the them or both so check it here for previously we have done this part and many things you can learn from other blog article.

     

    Click Here 

     

    Containers vs Images


    This is one of the most common Docker interview questions.


    • Docker Image


    An Image is like a blueprint or template.



    Think of it like:

    Windows ISO File
         ↓
    Install Windows
         ↓
    Running Windows OS
      



    Similarly:
    Docker Image
        ↓
    Run Image
        ↓
    Docker Container
    




    Examples of Images:

    • nginx
    • ubuntu
    • mysql
    • node



    View downloaded images:

    • docker images




    Example output:


    docker-installation-images-containers-port-mapping-guide

     

    Docker Container



    A Container is a running instance of an image or Containers are standardized software units that package code and dependencies together, ensuring an application runs quickly and reliably across any computing environment. 


    Example:

    • docker run nginx


    Docker:

    • Checks for nginx image
    • Downloads it if missing
    • Creates container
    • Starts container


    View running containers:  list running container and verify 

    docker ps

     

     docker-installation-images-containers-port-mapping-guide

     

     

     Interview Answer


    What is the difference between Image and Container?



    Image


    • Read-only template
    • Used to create containers
    • Similar to an ISO file



    Container

    • Running instance of an image
    • Has its own process and network
    • Similar to an installed/running operating system

     

     

    Pull Images



    What is Pull?

    Downloading an image from Docker Hub to your local machine.

    Example:

    docker pull nginx


    Docker downloads:

    • nginx:latest
    • Pull Ubuntu
    • docker pull ubuntu



    Check downloaded images:

    • docker images
    • Pull Specific Version
    • docker pull nginx:1.27




    Why?


    In production we often use specific versions instead of latest.


    Interview Question



    What does docker pull do?

    Answer:

    docker pull downloads an image from a registry such as Docker Hub to the local Docker host.

    like this hello-world repo or registry -





    docker-installation-images-containers-port-mapping-guide



     Port Mapping


    This is extremely important.



    Without Port Mapping


    Run nginx:

    • docker run nginx
    • Container runs internally.
    • You cannot access it from your browser.


    With Port Mapping

    • docker run -d -p 8080:80 nginx






    Meaning:

    • Host Machine Port = 8080
    • Container Port = 80



    Visualization:


    Your Laptop
    localhost:8080
            │
            ▼
    Docker Container
    Port 80 (Nginx)



    Test


    Open browser:

    http://localhost:8080

    You should see:

    Welcome to nginx!



    docker-installation-images-containers-port-mapping-guide






    Another Example


    Node.js app running on port 3000 inside container:

    • docker run -d -p 3000:3000 myapp



    Meaning:

    • Host 3000 → Container 3000
    • Check Port Mapping
    • docker ps



    Example:

    PORTS

    • 0.0.0.0:8080->80/tcp



    Meaning:

    Host Port 8080
               ↓
    Container Port 80


     

     

    Commands You Must Remember



    Pull image:

    • docker pull nginx


    List images:

    • docker images


    Run container:

    • docker run nginx


    Run in background:

    • docker run -d nginx


    Port mapping:

    • docker run -d -p 8080:80 nginx


    Running containers:

    • docker ps



    All containers:

    • docker ps -a





    Before moving to Week 2, make sure you can confidently explain:

    ✅ What is Docker?
    ✅ What is an Image?
    ✅ What is a Container?
    ✅ What is Docker Hub?
    ✅ What is docker pull?
    ✅ What is port mapping?
    ✅ Difference between docker ps and docker images?
    ✅ Meaning of 8080:80?

     

    Disclaimer



    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking. 
     
     
     
     
     
  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.