Jump to content

Docker/Tomcat

From Wikiversity

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]
  1. Use Play with Docker. Create an account and/or log in.
  2. Start an interactive session and add a new instance.
  3. In the terminal window, enter the following commands:
    • touch Dockerfile
    • touch index.jsp
  4. Use the Editor button to edit both files and save the contents above into each respective file.
  5. Run the following commands:
    • docker build -t tomcat-server .
    • docker run -d -p 8080:8080 --name=tomcat-server tomcat-server
  6. In the top window, select the 8080 button to connect to the running server.

On Your Own System

[edit | edit source]
  1. Install Docker Desktop or the Docker Engine.
  2. Save the files above into a new Docker Flask folder:
    • Dockerfile
    • index.jsp
  3. 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
  4. Open a web browser to connect to the running server:

See Also

[edit | edit source]