Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DevOps Lifecycle
  • DevOps Roadmap
  • Docker Tutorial
  • Kubernetes Tutorials
  • Amazon Web Services [AWS] Tutorial
  • AZURE Tutorials
  • GCP Tutorials
  • Docker Cheat sheet
  • Kubernetes cheat sheet
  • AWS interview questions
  • Docker Interview Questions
  • Ansible Interview Questions
  • Jenkins Interview Questions
Open In App
Next Article:
Docker - Deploying WebApps on Docker
Next article icon

Docker - Deploying WebApps on Docker

Last Updated : 14 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Docker applies abstraction at the software layer of the operating system to create an instant and portable environment that includes everything you need: a Linux kernel, libraries, system tools like grep or sshfs, plus applications (web servers/services) and all dependencies needed by those applications (e.g., database engines). When deployed, these containers are all bundled up and run in a single, isolated process. The benefits stem from using containers rather than virtual machines and enabling you to run the exact same application production environment on different servers without modifying it (or without having to purchase servers for every deployment).

Running Your Web Apps in Docker Containers

Using the right tools ensures that you are going to be delivering a great user experience, and if you want that experience to be easier and more consistent across all your environments, you should consider Docker. The developer community has been successful in growing open-source tools and frameworks in many industries because they allow companies to rapidly iterate on their products without having to go through expensive tooling investments. The environments Docker creates are not the same as virtual machines, but the benefits you will see when you use them should outweigh these costs.

  • Containerization vs Virtualization: Docker uses "containers" for its containers. Containers are basically a mechanism for labeling resources with a namespace. For example, an application's database and all of its files would be stored under a container's file system namespace. What this means is that Docker makes it easier to deploy your applications on any machine. Docker also provides isolation between containers and makes life easier for deployment automation tooling by providing a safe, consistent environment to run in (the Docker daemon creates this environment automatically).
  • Single Process Containers versus Multiple Process Containers: Docker is not a single-process containerization framework. It does not automatically create processes for each of your applications. Instead, it creates a container for each running application and allows you to manage a process tree. Applications can still be written as multiple processes, and Docker will intelligently link them together (in the same way that multiple processes are linked together under the same application). 
  • Built by Docker, Not for Stopping Docker: Docker currently does not have great integration with other environments or systems like Google App Engine or Heroku. Docker is focused on the developer, and it is important to think about how your application will be run. Do you want to run your app in a secure, robust environment? If so, Docker is not for you.
  • No support for lots of containers: Docker currently has only limited support for scaling and auto-scaling containers across multiple hosts. Additionally, Docker does not do any type of load balancing or failover. These are important features in production environments because they allow you to scale out as needed without having to manually rebuild all of your containers (failure and availability). Support for this kind of orchestration will come with time, though.

Prerequisite

Docker is an open-source containerization platform for apps and services. It allows developers to build, ship, and run any application in a consistent, reproducible way across whatever machines they choose. It was developed by Solomon Hykes in 2013 while working at dotCloud as a way to speed up their development process.

  • Docker Images: Instead of working directly with an application's code, developers work with something called "Docker images," which are templates for building out containers—full environments where containers can be started, stopped, and otherwise manipulated. These containers are what is actually executed on the server.
  • Containers: Containers are lightweight, resource-isolated instances that run in parallel to other containers. They can be started and stopped quickly and do not require any additional resources to run. Each container is an isolated process running within a single kernel (OS process). These processes can share resources with other containers running on the same host, but they cannot communicate directly by address space or sockets. The host namespaces provide a way to share host system resources without compromising the isolation of containers.
  • Docker Compose: Docker Compose is a tool that helps you define, build and run Docker applications from an easy-to-use YAML file. By taking advantage of the Docker remote API, Composer makes it super simple to create and manage your applications.

When should Docker be used?

Docker is not a replacement for virtual machines, but rather a way for you to use containers and host your larger web applications closer to their users. Docker's greatest advantage is that it can help you scale out your applications, which means more instances running at any given time. It also provides isolation between containers so that they don't step on each other.

Why Web Apps? 

Web applications are the most prevalent types of applications built in the 21st century, and they are a great way for organizations to expand their reach and increase their revenue. Web apps have the potential to become more convenient and seamless than ever with services like Google Docs or Salesforce.com. You may want to take advantage of Docker in order to do this.

When Not To Use Docker?

You might want to consider using Docker if you need to run multiple instances of your application on a single host. You may also want to look into other tools like systemd containers support, rkt (pronounced as "rocket", a CLI tool for running app containers on Linux) written from scratch for security and ease of use, or lightweight Hypervisor VirtualBox.

Step-By-Step Processes to Deploy WebApps On Docker: Complete Tutorial

First we need to install the docker on the servers for that refer tot he following

  • How to Install Docker on Windows?
  • How To Install and Configure Docker in Ubuntu?

Step 1: Creating Dockerfile

Dockerfiles are meant to be used from within the terminal, in a text editor, or on the command line. Compilers include support for defining programs by embedding a text representation of an executable image into a Dockerfile. The result is an entirely self-contained container image. However, it opens you up to vulnerabilities that could potentially give outside parties access to your source code or private keys if someone were to hack or brute-force your Docker daemon. 

FROM tomcat:8.0.43-jre8 COPY target/helloworld.war /usr/local/tomcat/webapps/ EXPOSE 8080 RUN chmod +x /usr/local/tomcat/bin/catalina.sh CMD ["catalina.sh", "run"]
  • FROM tomcat:8.0.43-jre8: Specifies the base image to use, which is Tomcat version 8.0.43 with Java Runtime Environment (JRE) version 8.
  • COPY target/helloworld.war /usr/local/tomcat/webapps/: The `COPY` command moves the `helloworld.war` file from the local `target` folder into the `webapps` directory of Tomcat within the Docker container, allowing Tomcat to deploy the application automatically.
  • EXPOSE 8080: Informs Docker that the container listens on port 8080 at runtime. This does not actually publish the port; it serves as documentation for users about which ports are intended to be published.
  • RUN chmod +x /usr/local/tomcat/bin/catalina.sh: This command ensures the `catalina.sh` script has execute permissions, allowing Tomcat to start properly inside the container.
  • CMD ["catalina.sh", "run"]: Specifies the command to run when the container starts. In this case, it runs the catalina.sh script with the argument run, which starts Tomcat and makes it serve the deployed web application

Step 2: Containerize your application

Build a Docker Image of your web app.

$ docker build -t [image name] .
docker build -t mywebapp .
build_mywebapp

List the Docker Images

docker images
docker-images

Step 3: Push the docker image to a docker repository

Login to docker hub

docker login
docker_login

Retag docker image

docker tag [existing_image_name:tag] [new_image_name:tag]
Retag-docker-image

Push docker image

docker push username/image_name
push docker image

Step 4: Pull the docker image and run in Linux

To pull and run a Docker image in Linux, use the docker run command with the image name. This command automatically pulls the image if it's not available locally and starts a container based on that image.

  • Pull the image from the hub using the below command
docker pull  username/image_name
pull docker image
  • Run the docker image using the below command as shown image below.
docker  run -d -it -p 8080:8080 image_name:tag
run-docker

This docker run command creates and runs a new Docker container based on the specified image. Let's break down the options:

  • -i: Keeps STDIN open even if not attached.
  • -t: Allocates a pseudo-TTY, which allows you to interact with the container's shell.
  • -d: Detaches the container and runs it in the background.
  • -p 8080:8080: Maps port 8080 of the host machine to port 8080 of the container.
  • image_name:tag: Specifies the name and tag of the Docker image used to create the container.

Step 5: Access the docker container

To access a Docker container from an EC2 instance and localhost, you need to ensure that the container is running and exposed on a port accessible from both the EC2 instance and localhost. Once the container is running and the port is exposed, you can use the EC2 instance's public IP or DNS name to access the container from the EC2 instance, and you can use localhost or public ip along with the mapped port to access the container from localhost.

apache_tomcat

Next Article
Docker - Deploying WebApps on Docker

S

sarithak5br5
Improve
Article Tags :
  • Docker
  • DevOps

Similar Reads

    Docker Tutorial
    Docker is a tool that simplifies the process of developing, packaging, and deploying applications. By using containers, Docker allows you to create lightweight, self-contained environments that run consistently on any system, minimising the time between writing code and deploying it into production.
    7 min read

    Introduction

    What is Docker?
    Have you ever wondered about the reason for creating Docker Containers in the market? Before Docker, there was a big issue faced by most developers whenever they created any code that code was working on that developer computer, but when they try to run that particular code on the server, that code
    12 min read
    Features of Docker
    Pre-requisite: Docker Docker is one of the most popular open-source sets of platforms for developing and automating the deployment of applications. It deploys applications into containers and enables us to separate our applications from infrastructure. It is designed to provide a lightweight and fas
    4 min read
    Architecture of Docker
    Pre-requisite: DockerDocker makes use of a client-server architecture. The Docker client talks with the docker daemon which helps in building, running, and distributing the docker containers. The Docker client runs with the daemon on the same system or we can connect the Docker client with the Docke
    4 min read
    What is Docker Hub?
    Docker Hub is a repository service and it is a cloud-based service where people push their Docker Container Images and also pull the Docker Container Images from the Docker Hub anytime or anywhere via the internet. It provides features such as you can push your images as private or public. Mainly De
    12 min read
    What is Docker Cloud?
    Docker is a software platform that provides some special kind of facilities, like a service provider that allows you to build, test, and deploy your application in centralized processing and quickly. So, the Docker Cloud is basically working as a service provider by Docker in which we can perform su
    10 min read

    Docker Installation

    Docker - Installation on Windows
    In this article, we are going to see how to install Docker on Windows. On windows if you are not using operating system Windows 10 Pro then you will have to install our docker toolbox and here docker will be running inside a virtual machine and then we will interact with docker with a docker client
    2 min read
    How to Install Docker using Chocolatey on Windows?
    Installing Docker in Windows with just the CLI is quite easier than you would expect. It just requires a few commands. This article assumes you have chocolatey installed on your respective windows machine. If not, you can install chocolatey from here. Chocolatey is a package manager for the Windows
    4 min read
    How to Install and Configure Docker in Ubuntu?
    Docker is a platform and service-based product that uses OS-level virtualization to deliver software in packages known as containers. Containers are separated from one another and bundle their software, libraries, and configuration files. Docker is written in the Go language. Docker can be installed
    6 min read
    How to Install Docker on MacOS?
    Pre-requisites: Docker-Desktop Docker Desktop is a native desktop application for Windows and Mac's users created by Docker. It is the most convenient way to launch, build, debug, and test containerized apps. Docker Desktop includes significant and helpful features such as quick edit-test cycles, fi
    2 min read
    How to install and configure Docker on Arch-based Linux Distributions(Manjaro) ?
    In this article, we are going to see how to install and configure Docker on Arch-based Linux Distributions. Docker is an open-source containerization platform used for building, running, and managing applications in an isolated environment. A container is isolated from another and bundles its softwa
    2 min read
    How to Install Docker-CE in Redhat 8?
    Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all the parts it needs, such as libraries and other dependencies, and deploy it as one package. Installing Docker-CE in Redhat 8: St
    2 min read

    Docker Commands

    Docker Commands
    Docker is an open-source project that automates the deployment of applications as movable, independent containers that can run locally or in the cloud. You can divide your applications from your infrastructure with the help of Docker, allowing for quick software delivery and it also allows you to ma
    7 min read
    How to Install Docker using Chocolatey on Windows?
    Installing Docker in Windows with just the CLI is quite easier than you would expect. It just requires a few commands. This article assumes you have chocolatey installed on your respective windows machine. If not, you can install chocolatey from here. Chocolatey is a package manager for the Windows
    4 min read
    How to Install and Configure Docker in Ubuntu?
    Docker is a platform and service-based product that uses OS-level virtualization to deliver software in packages known as containers. Containers are separated from one another and bundle their software, libraries, and configuration files. Docker is written in the Go language. Docker can be installed
    6 min read
    How to Install Docker on MacOS?
    Pre-requisites: Docker-Desktop Docker Desktop is a native desktop application for Windows and Mac's users created by Docker. It is the most convenient way to launch, build, debug, and test containerized apps. Docker Desktop includes significant and helpful features such as quick edit-test cycles, fi
    2 min read
    How to install and configure Docker on Arch-based Linux Distributions(Manjaro) ?
    In this article, we are going to see how to install and configure Docker on Arch-based Linux Distributions. Docker is an open-source containerization platform used for building, running, and managing applications in an isolated environment. A container is isolated from another and bundles its softwa
    2 min read
    How to Install Docker-CE in Redhat 8?
    Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all the parts it needs, such as libraries and other dependencies, and deploy it as one package. Installing Docker-CE in Redhat 8: St
    2 min read

    Docker Commands

    Docker Commands
    Docker is an open-source project that automates the deployment of applications as movable, independent containers that can run locally or in the cloud. You can divide your applications from your infrastructure with the help of Docker, allowing for quick software delivery and it also allows you to ma
    7 min read
    Running Commands Inside Docker Container
    If you are working on an application inside the Docker Container, you might need commands to install packages or access file system inside the Docker Container. Executing commands inside Docker Containers should be easy enough for you since you have to do it multiple times across your development ph
    6 min read
    Docker - USER Instruction
    By default, a Docker Container runs as a Root user. This poses a great security threat if you deploy your applications on a large scale inside Docker Containers. You can change or switch to a different user inside a Docker Container using the USER Instruction. For this, you first need to create a us
    2 min read

    Docker Images

    What is Docker Image?
    Docker Image is an executable package of software that includes everything needed to run an application. This image informs how a container should instantiate, determining which software components will run and how. Docker Container is a virtual environment that bundles application code with all the
    10 min read
    Working with Docker Images
    If you are a Docker developer, you might have noticed that working with multiple Docker Images at the same time might be quite overwhelming sometimes. Managing numerous Docker Images all through a single command line is a very hefty task and consumes a lot of time. In this article, we are going to d
    2 min read
    Docker - Publishing Images to Docker Hub
    Docker is a container platform that facilitates creating and managing containers. In this article, we will see how docker stores the docker images in some popular registries like Dockerhub and how to publish the Docker images to Docker Hub. By publishing the images to the docker hub and making it pu
    8 min read
    Docker Commit
    Docker is an open-source container management service and one of the most popular tools of DevOps which is being popular among the deployment team. Docker is mostly used in Agile-based projects which require continuous delivery of the software. The founder, Chief Technical Officer, and Chief Archite
    10 min read
    Docker - Using Image Tags
    Image tags are used to describe an image using simple labels and aliases. Tags can be the version of the project, features of the Image, or simply your name, pretty much anything that can describe the Image. It helps you manage the project's version and lets you keep track of the overall development
    7 min read
    Next.js Docker Images
    Using Next.js Docker images allows your app to deploy to multiple environments, and is more portable, isolated and scalable in dev and prod. Docker’s containerization makes app management super easy, you can move from one stage to another with performance.Before we get started, let’s cover the basic
    14 min read
    How to Use Local Docker Images With Minikube?
    Minikube is a software that helps in the quick setup of a single-node Kubernetes cluster. It supports a Virtual Machine (VM) that runs over a docker container and creates a Kubernetes environment. Now minikube itself acts as an isolated container environment apart from the local docker environment,
    7 min read

    Docker Compose

    Docker Compose
    An open-source platform called Docker makes designing, shipping, and deploying applications simple. It runs an application in an isolated environment by compiling its dependencies into a so-called container. for additional information on Docker. In a normal case, several services, such as a database
    15+ min read
    Docker Compose Tool To Run aMulti Container Applications
    The article talks about how to run multi-container applications using a single command. Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you can configure a file (YAML file) to configure your docker containers. Then Once you configured the Yaml fil
    8 min read

    Docker Engine, Storage

    Data Storage in Docker
    Docker images are built-in form of layers and docker containers store all the data being used, on the container writable layer which is only persisted till the lifespan of the container i.e. it is no longer accessible once the container is removed. This also makes it difficult to get the data out of
    4 min read
    Data Storage in Docker
    Docker images are built-in form of layers and docker containers store all the data being used, on the container writable layer which is only persisted till the lifespan of the container i.e. it is no longer accessible once the container is removed. This also makes it difficult to get the data out of
    4 min read
    Backing up a Docker Container
    If you are a Docker Developer, you would surely know how important it is to backup your Docker Container file system. If you are working on an important Docker Application, it becomes very necessary to backup all the files and folders related to it so that in case anything goes wrong, you can get ba
    2 min read
    Using CLI to Manage Docker Volumes
    If you want to share files and directories among multiple Docker Containers, you can easily mount Docker Volumes to different Containers. However, managing such a large number of Docker Volumes becomes very difficult at times. In this article, we are going to discuss how to manage Docker Volumes by
    7 min read

    Docker Networking

    Docker Networking
    Pre-requisite: Docker Docker Networking allows you to create a Network of Docker Containers managed by a master node called the manager. Containers inside the Docker Network can talk to each other by sharing packets of information. In this article, we will discuss some basic commands that would help
    5 min read
    Docker - Managing Ports
    Pre-requisites: Docker Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers. These containers may need to talk to each other or to services outside docker, for this we not only need to run the image but also expose the c
    4 min read
    Creating a Network in Docker and Connecting a Container to That Network
    Networks are created so that the devices which are inside that network can connect to each other and transfer of files can take place. In docker also we can create a network and can create a container and connect to the respective network and two containers that are connected to the same network can
    2 min read
    Connecting Two Docker Containers Over the Same Network
    Whenever we expose a container's port in docker, it creates a network path from the outside of that machine, through the networking layer, and enters that container. In this way, other containers can connect to it by going out to the host, turning around, and coming back in along that path.Docker of
    3 min read
    How to use Docker Default Bridge Networking?
    Docker allows you to create dedicated channels between multiple Docker Containers to create a network of Containers that can share files and other resources. This is called Docker Networking. You can create Docker Networks with various kinds of Network Drivers which include Bridge drivers, McVLAN dr
    7 min read
    Create your own secure Home Network using Pi-hole and Docker
    Pi-hole is a Linux based web application, which is used as a shield from the unwanted advertisement in your network and also block the internet tracking system. This is very simple to use and best for home and small office networks. This is totally free and open-source. It also allows you to manage
    3 min read

    Docker Registry

    What is Docker Registry?
    Docker Registry is a centralized storage and distributed system for collecting and managing the docker images. It provides both public and private repositories as per the choice whether to make the image accessible publicly or not. It is an essential component in the containerization workflow for st
    10 min read
    Docker - Using Public Repositories To Host Docker Images
    Docker is a software platform for creating isolated virtualized environments for building, deploying, and testing applications with ease. In this tutorial, we will learn how to host public repositories on docker hub which is a hosted repository service provided by Docker for finding and sharing cont
    10 min read
    Docker - Private Registries
    Pre-requisites: Docker, Docker HUB Docker registry is your own private repository where you can store your own Docker images and share them with others. Docker Registry is basically organized into Docker Repositories. Within the docker Repository, you can maintain specific versions of a Docker Image
    3 min read
    Creating a Private Repository and Push an Image to That Private Repository
    In this article, we show how to create a docker hub account and pull the image from the docker hub repository and push our image to the docker hub repository. As the docker hub is a public repository that can be accessed by anyone so one can create their own private repository to which they can push
    2 min read
    Docker - Using Public Repositories To Host Docker Images
    Docker is a software platform for creating isolated virtualized environments for building, deploying, and testing applications with ease. In this tutorial, we will learn how to host public repositories on docker hub which is a hosted repository service provided by Docker for finding and sharing cont
    10 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences