How to get tomcat log from docker container running in atomic host - docker

I am working on Log monitoring, I have requirement of getting tomcat application server logs(example: catalina.log) running in the docker container(container is running in atomic host) and passing it to Logstash server using rsyslog.
I am able to get the docker container related logs, but not able to get the tomcat server and application logs from the docker container where tomcat is running.
Any suggestion on this is appreciated.
Thanks,
Praveen

You could mount the local host when initializing the container. You just pass -v flag for mounting to the local host.
docker run -v /tmp may/hello-world.py
This will allow you to mount the directory of the tomcat logs to the local host.
Here is the Docker Docs that talks about it.
https://docs.docker.com/engine/userguide/containers/dockervolumes/
-Bruce

Related

Unable to access Jenkins container outside of host network

I am stuck in a step. I am using an ubuntu vm which is in Azure cloud through terminal; don't have UI access. There I have installed docker and pulled the jenkins image. I have mapped this container from my host machine by running following command - docker run -p 8080:8080 jenkins to access this jenkins from my MAC using Ubuntu IP address:8080, however I am getting the This site cannot be reached. So do I am following or missed any steps to mapped the container outside of docker host machine? Please help!

No connectivity between EC2 instance and Docker container

I have an EC2 instance (Ubuntu 16.04 ami-ba602bc2) deployed. I've installed docker on it and downloaded a Docker container that runs JasperReports in Tomcat. I've tested this Docker container on my laptop and it works correctly. I downloaded and started the Docker container on the EC2 instance with
docker run -itd -p 8080:8080 dwschulze/jasperreports.server.v7.1.ubuntu.16.04:latest
the same command I use locally to run on my laptop. docker ps shows the container running. I've opened port 8080 in the AWS security group.
I've also connected to the Docker container and verified that the tomcat instance is running.
I can't connect to the reports server from the internet. I've also tried telnet localhost 8080 from the EC2 instance and it times out.
Everything I've read says that I should be able to run a Docker container on an EC2 instance, but it can't even connect locally.
Any ideas?
Thanks.
My problem was that I was running in a t2.small which is too small to even run Tomcat (let alone Jasper Reports) reliably. I switched to a t2.xlarge and problem solved.

Not able to access files in xampp htdocs installed in ubuntu docker container

I have installed xampp and deployed my php code in a docker image and started a container on ubuntu 14.04.
I cannot access my phpmyadmin by using my docker container system ip/phpmyadmin in host computer's firefox browser , but cannot take my web interface in browser. while try to access my web interface its shows as follows:
Access forbidden!
You don't have permission to access the requested object. bhla bhla....
Error 403
Note: I have already given required permissions to files in xampp/htdocs folder
Running a new container with sudo docker run -ti ubuntu will not bind any port. The option -p needs to be used to bind host-port from container-port.
See a more detailed answer.
In your case, assuming your web server is running on port 80 in the container and assuming you cant to access it from you host web browser on the port 9090 start the container with the command:
docker run -it -p 9090:80 ubuntu

COREOS error on Bare Metal Server (unix socket /var/run/docker.sock does not exist)

I´ve installed CoreOs on BareMetal (dedicated 16GB, 4cores Atom). Docker is running and despite the fact that simple bash instructions run properly, when launching dockerui images downloaded form the hub I get the /var/run/docker.sock not found.
The sock file is present and docker daemon is running. When launching docker daemon in interactive shell I get no error from the daemon; but the error is coming from the client requesting running the image.
I bet the container you downloaded expects the docker socket to be mounted in as a volume, so that I can control it or issue docker commands.
Check that the docs you are following don't have docker run -v flag in them.

Obtaining the ip address of a docker container

I have a ubuntu machine which is a VM where I have installed docker in it. I am using this machine from my local windows machine and doing ssh , opening the terminal to the ubuntu machine.
Now , I am going to take a docker image which contains all the necessary softwares for eg: apache installed in it. Later I am going to deploy a sample appication(which is a web applicationP on to it and save it .
Now , I am in a confused mode as in how to check the deployed application if its running properly. i.e., what would be the address of the container which containds the deployed application.
for eg:- If I type http://127.x.x.x which is the address of the ubuntu machine , I am just getting time out .
Can anyone tell me how to verify the deployed application . Also, the printing the output of the program on the console works seemlessly fine , as the output gets printed , only thing I have some doubts is regarding the web application.
There are some possibilities to check whether your app is running.
Remote API
As JimiDini said, one possibility is the Docker remote API. You can use it to see all running containers (which would be your use case, right?), inspect a certain container or start and stop containers. The API is a REST-API with several binding for programming languages (at https://docs.docker.io/reference/api/remote_api_client_libraries/). Some of them are very outdated. To use the Docker remote API from another machine, I needed to open it explicitly:
docker -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock -d &
Note that the API is open to the world now! In a real scenario you would need to secure it in some way (e.g. see the example at http://java.dzone.com/articles/securing-docker%E2%80%99s-remote-api).
Docker PS
To see all running containers run docker ps on your host. This will list all running containers. If you do not see your app, it is not running. It also shows you the ports your app is exposing. You can also do this via the remote API.
Logs
You can also check the logs. You can run docker attach <container id> to attach to a certain container an see its stdout. You can run also run docker logs <container id> to receive the Docker logs. What I prefer is to write the logs to a certain directory, e.g. all logs to /var/log and mount this folder to my host machine. Then all your logs will end up in /home/ubuntu/docker-logs on your host.
docker run -p 80:8080 -v /home/ubuntu/docker-logs:/var/log:rw my/application
One word to ports and IP
Every container will get its own IP address. You can check this IP address via the remote API or via Docker on the host machine directly. You can also specify a certain host name for the container (by passing the --hostname="test42" to the run command). However, you mostly did not need that.
To access the application in the container, you need to open the port in the container and bind to a port on the host.
In your Dockerfile you need to EXPOSE the port your app runs on:
FROM ubuntu
...
EXPOSE 8080
CMD run-my-app.sh
When you start your container, you need to bind this port to a port of the host:
docker run -p 80:8080 my/application
Now you can access your app on http://localhost:80 or http://127.0.0.1:80.
If you app does not response, check if the container is running by typing docker ps or the remote API. If it is not running, check the logs for the reason.
(Note: If you run your Ubuntu VM in something like VirtualBox and you try to access it from your Windows machine, make sure you opened the ports in VirtualBox too!).
Docker container has a separate IP address. By default it is private (accessible only from the host-machine).
Docker provides all metadata (including IP address) via its API:
https://docs.docker.io/reference/api/docker_remote_api_v1.10/#inspect-a-container
https://docs.docker.io/reference/api/docker_remote_api_v1.10/#monitor-docker-s-events
You can also take a look at a little tool called docker-gen for inspiration. It monitors docker-events and created configuration-files on host machine using templates.
To obtain the ip address of a docker container, if you know its id (a long hex string) or if you named it:
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-id-or-name>
Docker is running its own network and to get information about it you can run the following commands:
docker network ls
docker network inspect <network name>
docker inspect <container id>
In the output, you should be able to find the IP.
But there is also a couple of things you need to be aware of, regarding Dockerfile and docker run command:
when you EXPOSE a port in Dockerfile, the service in the container is not accessible from outside Docker, but from inside other Docker containers
and when you EXPOSE and use docker run -p ... flag, the service in the container is accessible from anywhere, even outside Docker
So for example, if your apache is running on port 8080 you should expose it in Dockerfile and then you can run it as:
docker run -d -p 8080:8080 <image name> and you should be able to access it from your host on HTTP://localhost:8080.
It is an old question/answer but it might help somebody else ;)
working as of 2020
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

Resources