Docker/Tomcat
Appearance
< Docker
Dockerfile
[edit | edit source]# Configures a Tomcat web server and copies the current folder content
# to use as webapps/ROOT.
# Use the following commands to build and run the server.
# docker build -t tomcat-server .
# docker run -d -p 8080:8080 --name=tomcat-server tomcat-server
# Then open a web browser and connect to http://localhost:8080 .
# References:
# https://hub.docker.com/_/tomcat
# https://cs.brynmawr.edu/~dkumar/JSP/
FROM tomcat:alpine
WORKDIR /usr/local/tomcat/webapps/ROOT
COPY . .
EXPOSE 8080
CMD ["catalina.sh", "run"]
index.jsp
[edit | edit source]<%
// Displays "Hello world!"
//
out.print("Hello world!");
%>
Try It
[edit | edit source]Online Free
[edit | edit source]- Use Play with Docker. Create an account and/or log in.
- Start an interactive session and add a new instance.
- In the terminal window, enter the following commands:
touch Dockerfile
touch index.jsp
- Use the
Editor
button to edit both files and save the contents above into each respective file. - Run the following commands:
docker build -t tomcat-server .
docker run -d -p 8080:8080 --name=tomcat-server tomcat-server
- In the top window, select the
8080
button to connect to the running server.
On Your Own System
[edit | edit source]- Install Docker Desktop or the Docker Engine.
- Save the files above into a new
Docker Flask
folder:Dockerfile
index.jsp
- At a command prompt, change to the
Docker Flask
folder and then run the following commands:docker build -t tomcat-server .
docker run -d -p 8080:8080 --name=tomcat-server tomcat-server
- Open a web browser to connect to the running server: