Logs of a docker container - docker

Where does docker store it logs in the host machine as well as in the docker container. I know you can use docker logs . I want to know what is the physical location. Here is any example to illustrate more. I have got a java application which is generating standard output logs. I am using the following script to run it on a docker container
#!/bin/bash
nohup java -jar /opt/pubsub/publish.jar &
java -jar /opt/pubsub/subscribe.jar
I am unable to find my nohup in the container however I can see the content of nohup using docker logs . So where is my nohup??
Secondly where are the logs which are generated by docker itself?

They are stored in /var/lib/docker/containers
You can try docker-ci, it offers a solution to logging. It will watch the logs and send it to the client.
I hope this will help you.
http://docker-ci.org/documentation#remote-logging

Related

Docker/Ansible: ERROR! The playbook could not be found

I'm quite new to software development and having some issues setting up a docker container.
I've pull the docker container and run it. Now I want to apply some configuration to my container with
docker run --rm --network="ansible_default" -v C:\folder\folder1\ansible\playbooks:/ansible/playbooks docker.<address>/ansible ansible-playbook -i host localhost.playbook.yml
But when I run the above code, it just gives an error:
ERROR the playbook localhost.playbook.yml does not appear to be a file
I am running on administration powershell and have cd into the folder that contains the yaml files. (so inside C:\folder\folder1\ansible\playbooks)
Do I need ansible installed? Any pointers would be greatly appreciated!
EDIT: The docker container exits with a code 2, I'm supposed to be able to access it via localhost:8080 but it's just a blank screen. Exited(2) I'm not too sure what it means, haven't found much success online.
Turns out the solution is to reinstall Docker.

H2O Deep Water with Docker Container Template -> Flow UI not accesible

I started the Deep Water Docker container (CPU mode) on my Mac as described in the docs (https://github.com/h2oai/deepwater/blob/master/README.md):
docker run -it --rm -p 54321:54321 -p 8080:8080 -v $PWD:/host opsh2oai/h2o-deepwater-cpu
It starts correctly and without errors, but I cannot access the H2O UI at http://172.17.0.2:54321 ...
There is also a hint in the logs:
If you have trouble connecting, try SSH tunneling from your local machine 1. Open a terminal and run 'ssh -L 55555:localhost:54321 root#172.17.0.2'
2. Point your browser to http://localhost:55555
But this is also not working...
I use Docker CE Version 17.06.0-ce-mac19.
Any ideas what to do?
Here are the complete logs of starting H2O:
When you have started the docker image you have to start H2O manually. You do that with
java -jar /opt/h2o.jar &
For more info on this, please see https://github.com/h2oai/deepwater#pre-release-docker-image
In the side note: Please post the log, I can't tell what went wrong from this. It's possible that your Nvidia driver is too old.

My app can't create log files when it starts up inside Docker

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!
I don't know why your app isn't working, but can answer your questions-
Is there a way to see what user my app is starting up as?; or
A: Docker containers run as root unless otherwise specified.
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
A: Docker containers dump stdout/stderr to the Docker logs by default. There are two ways to see these- 1 is to run the container with the flag -it instead of -d to get an interactive session that will list the stdout from your container. The other is to use the docker logs *container_name* command on a running or stopped container.
docker attach 3f1492790397
This doesn't do what you are hoping for. What you want is docker exec (probably docker exec -it bootup bash), which will give you a shell in the scope of the container which will let you check for your log files or try and hit the app using curl from inside the container.
Why do I get no output?
Hard to say without the info from the earlier commands. Is your app listening on 0.0.0.0 or on localhost (your laptop browser will look like an external machine to the container)? Does your app require a supervisor process that isn't running? Does it require some other JAR files that are on the CLASSPATH on your laptop but not in the container? Are you running docker using Docker-Machine (in which case localhost is probably not the name of the container)?

Using Docker's CMD to run a Shell Script + Get Output

I've been using a docker file for about 6 months now without issue but after a few changes in compute engine, I'm hitting a weird issue where something in my start up script is behaving the way it should / it used to.
I have a shell script that does a couple tweaks to the environment before starting a web server which is started like so:
ADD src/docker/startup.sh /home/gauntface/docker/startup.sh
CMD /home/gauntface/docker/startup.sh
startup.sh echo's logs but I can't find a way to view these logs, does anyone have any advice?
docker logs shows nothing for my container
Additional Notes
I'm running the docker command with daemon mode. Without Daemon mode, docker throws this error:
the input device is not a TTY
The Docker file and start up script are here:
https://github.com/gauntface/gf-site/blob/staging/src/docker/Dockerfile-base
https://github.com/gauntface/gf-site/blob/staging/src/docker/startup.sh
docker logs by default will show the output from stdout/stderr:
$ docker run -it --name test-it busybox echo hello world
hello world
$ docker logs test-it
hello world
We'd need to know more about your shell script, what output it generates, and what debugging you've done to give a more detailed answer about why it's not working.

docker tomcat Log issue

Docker container can only to daemon mode: I run catalina.sh to start the tomcat.
But the problem is my log will not appear in catalina.out.
I can look at `docker logs , but this certainly cannot run in a production environment.
I would like to ask how, in production environment, can I have the Tomcat log stored in the document and without the container stopping?
If you look at the official tomcat docker image, it runs
CMD ["catalina.sh", "run"]
That is enough to starts tomcat in the foreground, displaying the logs on the console.
But, as you said, that might not populate catalina.out.
An alternative would be:
CMD service tomcat start && tail -f /var/lib/tomcat/logs/catalina.out
There are options in this (off topic) question to make the tomcat logs run in the foreground.
But to answer your actual question, the docker logs command is the usual way to get logs from a container. You can also find them on the host as they live in a file.
But the best way is to use an external logging service to collect and aggregate the logs, so you don't have to log in to the production server. Logentries is one example (though it's far from perfect). Splunk is another.
The Docker logging drivers docs may help.
You need to have one process running in foreground in docker container to have the container running.
I use a hack with all my docker images.
Create a script run.sh with the following code
#!/bin/sh
service tomcat start
tail -f /dev/null
Make sure before you run the run.sh file in docker, change the permissions.
Addition to Dockerfile will be
COPY run.sh ./run.sh
RUN chmod 755 ./run.sh
CMD ["./run.sh"]

Resources