search
HomeOperation and MaintenanceDockerHow to correctly deploy Tomcat and Web applications with docker

How to correctly deploy Tomcat and Web applications with docker

Dec 17, 2020 am 09:33 AM
dockertomcatweb application

How to correctly deploy Tomcat and Web applications with docker

The correct deployment method is as follows:

(Learning video sharing: Programming video)

1. Download docker online

yum install -y epel-release

yum install docker-io   # 安装dockerchkconfig docker on     # 加入开机启动service docker start     # 启动docker服务

2. Install Tomcat container with docker

2.1. Find the tomcat information of the server

# docker search tomcat

How to correctly deploy Tomcat and Web applications with docker

2.2 Download the official image with the highest Starts

docker pull  docker.io/tomcat

2.3 View all docker images

docker images

How to correctly deploy Tomcat and Web applications with docker

2.4 Start tomcat

docker run -p 8081:8080 docker.io/tomcat    #  若端口被占用,可以指定容器和主机的映射端口 前者是外围访问端口:后者是容器内部端口

How to correctly deploy Tomcat and Web applications with docker

2.5 Start Then you can access 192.168.138.132:8080

How to correctly deploy Tomcat and Web applications with docker

##3. Deploy your own web reference

docker ps     # 使用以下命令来查看正在运行的容器

How to correctly deploy Tomcat and Web applications with docker

3.1. Upload your own war package to the host

How to correctly deploy Tomcat and Web applications with docker

3.2. Execute to view the address in the container comcat

docker  exec -it   3cb492a27475   /bin/bash    #中间那个是容器id(CONTAINER_ID)

How to correctly deploy Tomcat and Web applications with docker

3.3 Put the war The packet is thrown to the host and then thrown into the container and thrown to tomcat/webapps

docker cp NginxDemo.war 3cb492a27475 :/usr/local/tomcat/webapps
3.4. Start tomcat or restart docker restart [Container ID]

docker run -p 8081:8080 docker.io/tomcat
3.5 Check the started image

docker ps

How to correctly deploy Tomcat and Web applications with docker

3.6 Execute to view the projects in the container comcat

docker  exec -it   3cb492a27475   /bin/bash    #中间那个是容器id(CONTAINER_ID) cd /webapps

ls   # 即可查看到我们的项目了
3.7 A drawback of the above execution is that the project will no longer be available after the container is restarted. The following is the method 2 to start. Start by mounting

docker run -d -v /usr/docker_file/NginxDemo.war:/usr/local/tomcat/webapps/NginxDemo.war -p 8080:8080 docker.io/tomcat
3.8 The first two methods are recommended to be used in the test environment. After all, the code needs to be modified frequently. Method 3 can be used in production. It is also the method recommended by the official website

vi Dockerfile

from docker.io/tomcat:latest    #你的 tomcat的镜像MAINTAINER XXX@qq.com    #作者COPY NginxDemo.war   /usr/local/tomcat/webapps  #放置到tomcat的webapps目录下

How to correctly deploy Tomcat and Web applications with docker

3.8.1 Generate a new image:

docker build -t nginx-demo:v1 .

How to correctly deploy Tomcat and Web applications with docker

3.8.2 Start a new image

docker run -p 8080:8080 nginx-demo:v1

How to correctly deploy Tomcat and Web applications with docker

Others

# 基本信息查看 docker version
# 查看docker的版本号,包括客户端、服务端、依赖的Go等 docker info  
# 查看系统(docker)层面信息,包括管理的images, containers数等
Related recommendations:

docker tutorial

The above is the detailed content of How to correctly deploy Tomcat and Web applications with docker. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete
Docker vs. Virtual Machines: A ComparisonDocker vs. Virtual Machines: A ComparisonMay 09, 2025 am 12:19 AM

Docker and virtual machines have their own advantages and disadvantages, and the choice should be based on specific needs. 1.Docker is lightweight and fast, suitable for microservices and CI/CD, fast startup and low resource utilization. 2. Virtual machines provide high isolation and multi-operating system support, but they consume a lot of resources and slow startup.

Docker's Architecture: Understanding Containers and ImagesDocker's Architecture: Understanding Containers and ImagesMay 08, 2025 am 12:17 AM

The core concept of Docker architecture is containers and mirrors: 1. Mirrors are the blueprint of containers, including applications and their dependencies. 2. Containers are running instances of images and are created based on images. 3. The mirror consists of multiple read-only layers, and the writable layer is added when the container is running. 4. Implement resource isolation and management through Linux namespace and control groups.

The Power of Docker: Containerization ExplainedThe Power of Docker: Containerization ExplainedMay 07, 2025 am 12:07 AM

Docker simplifies the construction, deployment and operation of applications through containerization technology. 1) Docker is an open source platform that uses container technology to package applications and their dependencies to ensure cross-environment consistency. 2) Mirrors and containers are the core of Docker. The mirror is the executable package of the application and the container is the running instance of the image. 3) Basic usage of Docker is like running an Nginx server, and advanced usage is like using DockerCompose to manage multi-container applications. 4) Common errors include image download failure and container startup failure, and debugging skills include viewing logs and checking ports. 5) Performance optimization and best practices include mirror optimization, resource management and security improvement.

Kubernetes and Docker: Deploying and Managing Containerized AppsKubernetes and Docker: Deploying and Managing Containerized AppsMay 06, 2025 am 12:13 AM

The steps to deploy containerized applications using Kubernetes and Docker include: 1. Build a Docker image, define the application image using Dockerfile and push it to DockerHub. 2. Create Deployment and Service in Kubernetes to manage and expose applications. 3. Use HorizontalPodAutoscaler to achieve dynamic scaling. 4. Debug common problems through kubectl command. 5. Optimize performance, define resource limitations and requests, and manage configurations using Helm.

Docker: An Introduction to Containerization TechnologyDocker: An Introduction to Containerization TechnologyMay 05, 2025 am 12:11 AM

Docker is an open source platform for developing, packaging and running applications, and through containerization technology, solving the consistency of applications in different environments. 1. Build the image: Define the application environment and dependencies through the Dockerfile and build it using the dockerbuild command. 2. Run the container: Use the dockerrun command to start the container from the mirror. 3. Manage containers: manage container life cycle through dockerps, dockerstop, dockerrm and other commands.

Docker and Linux: Building Portable ApplicationsDocker and Linux: Building Portable ApplicationsMay 03, 2025 am 12:17 AM

How to build portable applications with Docker and Linux? First, use Dockerfile to containerize the application, and then manage and deploy the container in a Linux environment. 1) Write a Dockerfile and package the application and its dependencies into a mirror. 2) Build and run containers on Linux using dockerbuild and dockerrun commands. 3) Manage multi-container applications through DockerCompose and define service dependencies. 4) Optimize the image size and resource configuration, enhance security, and improve application performance and portability.

Docker and Kubernetes: The Power of Container OrchestrationDocker and Kubernetes: The Power of Container OrchestrationMay 02, 2025 am 12:06 AM

Docker and Kubernetes improve application deployment and management efficiency through container orchestration. 1.Docker builds images through Dockerfile and runs containers to ensure application consistency. 2. Kubernetes manages containers through Pod, Deployment and Service to achieve automated deployment and expansion.

Docker vs. Kubernetes: Key Differences and SynergiesDocker vs. Kubernetes: Key Differences and SynergiesMay 01, 2025 am 12:09 AM

Docker and Kubernetes are leaders in containerization and orchestration. Docker focuses on container lifecycle management and is suitable for small projects; Kubernetes is good at container orchestration and is suitable for large-scale production environments. The combination of the two can improve development and deployment efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.