0

I'm unable to start Tomcat server from docker compose.

When I log into container using docker exec -it <container id> bash and see ps -eaf | grep "tomcat" it is showing empty. Tomcat server is not running.

docker-compose.yml file:

version: "3"
services:

  meghcore:  
    build: ./Core
    container_name: 'meghcore'
    expose:
      - '8080'
    ports:
      - '8080:8080'
    volumes:
      - meghcore:/opt/Tomcat1/webapps/

    command: /bin/bash
    tty: true
    stdin_open: true
    networks:
      - meghnet
volumes:  
  meghcore:
networks: 
  meghnet:
    driver: bridge

Dockerfile file:

FROM tomcat:8.5.35
WORKDIR /app
COPY . /app
RUN mv /app/*.war /opt/Tomcat1/webapps/
ENV PATH $PATH:/opt/Tomcat1/bin
WORKDIR /opt/Tomcat1/bin
EXPOSE 8080
CMD ["catalina.sh", "run"]
Szymon Jednac
  • 2,969
  • 1
  • 29
  • 43
Ramu
  • 1
  • 2

3 Answers3

0

Since you specify an alternate command: in your docker-compose.yml file, that overrides the CMD in the Dockerfile. You don't need most of the options you specify there at all, and several of them (the alternate command:, the volumes: overwriting the actual application) interfere with the normal container operation.

A complete, functional docker-compose.yml would be

version: "3"
services:
  meghcore:  
    build: ./Core
    ports:
      - '8080:8080'

None of the other options you list out are necessary. If there were other containers listed in the file, they could still communicate using their Docker Compose service names, without any special setup (another container in this same file could successfully call http://meghcore:8080).

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • thank you very much David Maze for for quick reply. I have a query here, if i remove volumes how can i persist my data? Also if i use above docker compose file i am unable to see running container in docker ps command. – Ramu Feb 12 '20 at 11:32
  • David can you please let me know correct docker compose and docker file script for creating a docker image with tomcat running and data persistence for my deployed application. – Ramu Feb 12 '20 at 11:42
  • You need to store data somewhere other than your `webapps` directory; good practice would be in a relational database (MySQL, PostgreSQL) that gets launched in parallel with your application (in the same `docker-compose.yml` file). Using a named volume as you show in the question is fine, but you can't mount it over your application `.war` file. – David Maze Feb 12 '20 at 12:09
0

What is happening is command specify in docker-compose.yml is overwriting the CMD provided in dockerfile.
kindly update command with the command available in dockerfile or remove command from docker-compose.yml

anand
  • 741
  • 5
  • 11
  • Thank you anand for your reply. if i remove command from docker-compose.yml file docker container exit with status 1. – Ramu Feb 12 '20 at 11:47
  • I will try to use your file but meanwhile, like I said, in that case, update the command with the information available in cmd. command: ["catalina.sh", "run"] – anand Feb 12 '20 at 11:52
  • kindly let us know whether the problem is solved or not, this will be helpful for the community. – anand Feb 12 '20 at 12:29
  • Thanks anand. problem is resolved. A you mentioned "command specify in docker-compose.yml is overwriting the CMD provided in dockerfile". Added below commands in dockerfile ENV JAVA_HOME=/usr/local/java/jdk1.8.0_212 ENV PATH $PATH:$JAVA_HOME/bin ENV PATH $PATH:/opt/Tomcat1/bin WORKDIR /opt/Tomcat1/bin EXPOSE 8080 CMD ["catalina.sh", "run"] – Ramu Feb 13 '20 at 09:08
0

Problem is resolved by adding below commands in dockerfile and removed command from docker compose file.

ENV PATH $PATH:$JAVA_HOME/bin
ENV PATH $PATH:/opt/Tomcat1/bin
WORKDIR /opt/Tomcat1/bin
EXPOSE 8080
CMD ["catalina.sh", "run"]
Ramu
  • 1
  • 2
  • the same I answered that docker-compose command is overwriting, but what you have updated in dockerfile is not meaningful, even with your previous dockerfile your tomcat should be running. So the answer you updated by yourself is irrelevant. – anand Feb 13 '20 at 10:19