I spent the weekend pouring over the Docker docs and playing around with the toy applications and example projects. I'm now trying to write a super-simple web service of my own and run it from inside a container. In the container, I want my app (a Spring Boot app under the hood) -- called bootup -- to have the following directory structure:
/opt/
bootup/
bin/
bootup.jar ==> the app
logs/
bootup.log ==> log file; GETS CREATED BY THE APP @ STARTUP
config/
application.yml ==> app config file
logback.groovy ==> log config file
It's very important to note that when I run my app locally on my host machine - outside of Docker - everything works perfectly fine, including the creation of log files to my host's /opt/bootup/logs
directory. The app endpoints serve up the correct content, etc. All is well and dandy.
So I created the following Dockerfile
:
FROM openjdk:8
RUN mkdir /opt/bootup
RUN mkdir /opt/bootup/logs
RUN mkdir /opt/bootup/config
RUN mkdir /opt/bootup/bin
ADD build/libs/bootup.jar /opt/bootup/bin
ADD application.yml /opt/bootup/config
ADD logback.groovy /opt/bootup/config
WORKDIR /opt/bootup/bin
EXPOSE 9200
ENTRYPOINT java -Dspring.config=/opt/bootup/config -jar bootup.jar
I then build my image via:
docker build -t bootup .
I then run my container:
docker run -it -p 9200:9200 -d --name bootup bootup
I run docker ps
:
CONTAINER ID IMAGE COMMAND ...
3f1492790397 bootup "/bin/sh -c 'java ..."
So far, so good!
My app should then be serving a simple web page at localhost:9200
, so I open my browser to http://localhost:9200
and I get nothing.
When I use docker exec -it 3f1492790397 bash
to "ssh" into my container, I see everything looks fine, except the /opt/bootup/logs
directory, which should have a bootup.log
file in it -- created at startup -- is instead empty.
I tried using docker attach 3f1492790397
and then hitting http://localhost:9200
in my browser, to see if that would generated some standard output (my app logs both to /opt/bootup/logs/bootup.log
as well as the console) but that doesn't yield any output.
So I think what's happening is that my app (for some reason) doesn't have permission to create its own log file when the container starts up, and puts the app in a weird state, or even prevents it from starting up altogether.
So I ask:
- Is there a way to see what user my app is starting up as?; or
- Is there a way to tail standard output while the container is starting? Attaching after startup doesn't help me because I think by the time I run the
docker attach
command the app has already choked
Thanks in advance!