Docker Compose Docker-Compose-Yml Command Multiline

Sure! The provided code snippet is meant to modify the Tomcat server information displayed when the server starts up. This can be achieved using Docker Compose by modifying the docker-compose.yml file as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
version: '3'
services:
  tomcat:
    image: tomcat:latest
    ports:
      - "8080:8080"
    command: >
      bash -c "mkdir -p /usr/local/tomcat/lib/org/apache/catalina/util/ &&
      echo server.info=PlantUML > /usr/local/tomcat/lib/org/apache/catalina/util/ServerInfo.properties &&
      catalina.sh run"      

In this Docker Compose configuration:

  • We define a service named tomcat based on the tomcat:latest image.
  • We map port 8080 from the host to port 8080 in the container to access the Tomcat server.
  • The command section is where the custom startup command is defined. The > character is used to allow multiline commands.

The custom command consists of the following steps:

  1. It creates the necessary directory structure using mkdir -p to ensure the directory exists.
  2. It uses echo to write the server.info property with the value PlantUML to the ServerInfo.properties file in the specified directory.
  3. Finally, it runs the catalina.sh run command to start the Tomcat server.

By specifying this custom command, you are modifying the Tomcat server information to display “PlantUML” as the server version when it starts up.

Make sure to place this modified docker-compose.yml file in the same directory where you run the docker-compose up command to start the Tomcat container with the specified custom command.

0%