How do I get to see elasticsearch own logs in a dockerized elasticsearch?

Dear community, i dockerized elasticsearch like this:

esnode1:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
container_name: esnode1
environment:
- node.name=esnode1
- cluster.name=es-on-docker
- discovery.seed_hosts=esnode2,esnode3
- cluster.initial_master_nodes=esnode1,esnode2,esnode3
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- node1data:/usr/share/elasticsearch/data
- node1logs:/usr/share/elasticsearch/logs
- ./config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
ports:
- 9200:9200
networks:
- elasticnet

ubuntu@smp-dev-dockerized-fra11-1:~/docker/config$ cat elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
path.logs: /usr/share/elasticsearch/logs

But under the /usr/share/elasticsearch/logs/ in the container (or on the mapped host) I only see gc.log(s) and NOT the 'normal' elasticsearch logs. How do I configure elasticsearch to get ALSO the its own, normal logs I usally have in non-docker elastic nodes? I hope I could make myself clear.
Thank you and kind regards
Stefano

Try docker logs

docker logs <container_id>

Thanks, docke logs worked, but I am still wondetting: if I go into the machine with docker exec -it bash and navigate to the usal logs directory I only see the gc.log and not the logs that I see with docker logs. Why is it so? Is there a possibility to have the logs in both ways / locations at the same time?
Thanks

Hi,

we are actually doing this in production. We use the following configuration:

See this docker-compose.yml snippet:

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
    volumes:
      - <local data folder path>:/usr/share/elasticsearch/data
      - <local logs folder path>:/usr/share/elasticsearch/logs
      - <local elasticsearch.yml>:/usr/share/elasticsearch/config/elasticsearch.yml
      - <local log4j2.properties>:/usr/share/elasticsearch/config/log4j2.properties

By doing this, you can freely configure log4j2.properties to configure logging in any way you please, and docker-compose logs (or docker logs) still works as expected.

Dear Gabriele,

thanks for your input - I will try it that way.
Saluti,
Stefano

Why is it so?

config/log4j2.properties in the docker image only enables console logging. Docker makes container's console logs available via docker logs.

Even if a container fails to start you can get console logs to debug the issue as docker retains those for some time. If logs are stored only in a container directory (not mounted) you will lose these logs if the container fails to start or after it terminates.

That makes sense - thanks all for the inputs.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.