1

I have a Dockerfile with the following commands:

FROM alpine:3.7

ENV CATALINA_HOME /usr/local/tomcat
ENV PATH $CATALINA_HOME/bin:$PATH

RUN apk update && \
apk add --no-cache openjdk8 && \
apk add --no-cache curl && \
mkdir -p "$CATALINA_HOME" && \
cd /tmp && \
curl -O https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.0.M26/bin/apache-tomcat-9.
tar xvzf apache-tomcat-9.0.0.M26.tar.gz -C . && \
mv apache-tomcat-9.0.0.M26/* "$CATALINA_HOME"

COPY tomcat-users.xml "$CATALINA_HOME"/conf/
COPY context.xml "$CATALINA_HOME"/webapps/manager/META-INF/

EXPOSE 8080

CMD ["catalina.sh", "start"]

I created the image by using the next command:

sudo docker build --tag tomcat_demo .

And to start the container I used:

sudo docker run -p 8080:8080 -dit tomcat_demo

Unfortunately at the end:

Exited (0) 19 seconds ago

Can you help me figure out why the service is not available and how can I make it available?

Mark
  • 5,994
  • 5
  • 42
  • 55
  • Run `sudo docker run -p 8080:8080 -it tomcat_demo` (removing the `-d` option) and show the resulting output. – BMitch Jan 03 '18 at 01:06

1 Answers1

1

You need to arrange for Tomcat (or another process) to run in the foreground. The catalina.sh start command is designed to work with a legacy init system and will automatically place Tomcat into the background. From Docker's perspective, it looks like your command has finished, so the container is cleaned up.

A simple way of handling this is to put an infinite sleep after start Tomcat:

CMD catalina.sh start; sleep inf

But a better way of solving it is to look at the other options available in catalina.sh, such as described in this answer:

CMD ["catalina.sh", "run"]
larsks
  • 277,717
  • 41
  • 399
  • 399