Docker Tomcat¶
Docker Tomcat refers to the deployment and management of the Apache Tomcat server within Docker containers. It typically involves using the official image available on the Docker Hub registry.^[600-developer-docker-docker-tomcat.md]
Image Acquisition¶
To utilize Tomcat in a Docker environment, the image can be pulled from the official repository using the standard pull command^[600-developer-docker-docker-tomcat.md]:
docker pull tomcat
Basic Usage¶
Once the image is available, it can be run in an interactive terminal session. The --rm flag ensures the container is automatically cleaned up upon exit^[600-developer-docker-docker-tomcat.md].
To run a specific version, such as Tomcat 8.0:
docker run -it --rm tomcat:8.0
To access the Tomcat service from the host machine, port mapping is required. The following command maps port 8080 inside the container to port 8888 on the host^[600-developer-docker-docker-tomcat.md]:
docker run -it --rm -p 8888:8080 tomcat:8.0
Container Persistence¶
When working with Dockerized Tomcat containers, it is important to distinguish between persisting an image and persisting a container state^[600-developer-docker-docker-tomcat.md].
Images (docker save)¶
The docker save command is used to persist an image to a tar archive. This is useful for backing up specific versions or transferring images offline^[600-developer-docker-docker-tomcat.md].
- List images:
docker images - Save image:
docker save busybox-1 > /home/save.tar^[600-developer-docker-docker-tomcat.md]
Containers (docker export)¶
The docker export command is used to persist a container (the filesystem state of a running instance)^[600-developer-docker-docker-tomcat.md].
- List all containers:
docker ps -a - Export container:
docker export <CONTAINER ID> > /home/export.tar^[600-developer-docker-docker-tomcat.md]
The corresponding command to import an exported container tar file is docker load^[600-developer-docker-docker-tomcat.md].
Related Concepts¶
- [[Docker]]
- [[Containerization]]
- [[Port Mapping]]
- DevOps
Sources¶
- 600-developer-docker-docker-tomcat.md