How can a nodejs process running inside a docker container, get that container's id?
the hostname seems to be the short container id in Docker v1.12
It works and this idea was found in this SO post.
// make sure your version on nodejs has the method
// NodeJS v6: https://nodejs.org/dist/latest-v6.x/docs/api/os.html
const os = require('os');
console.log( os.hostname() );
I wanted my worker container to run once and then die. Docker policy like restart:always
could then start a new one and this way I would ensure that mistakes in code would never cause data to leak from one job run to another. The memory space should be entirely sanitized/separate when the container is restarted.
But the way container logs were being colored and spit out on my console, made it seem like one worker run was handling multiple jobs before shutting down sometimes. This was supicious so I wanted to use container_id
to make sure that the log coloring wasn't throwing me off. Ultimately, this idea was no good because the same container_id is used across restarts so this wasn't a good way for me to debug or ascertain anything :(