Docker Differentiate multiple containers log folder at same host machine - docker

I am able to run a docker image and can connect log file in a container into a host machine volume .
I wonder how I can differentiate two containers of same running images at same host?
May be container ids can be used but I donot know how I can pass container id into log4j.xml file as a parameter?

Related

On Windows, where are the files of my CMS running with Docker?

I already found a command line to get a path of the files corresponding to my CMS (Prestashop) that runs with Docker, i.e:
docker exec -it <mycontainer> bash
But, it brings me to:
root#4c3cae74d5b1:/var/www/html#
Which looks like a Linux path. So, do you know how to know where the files are situated on my Windows file system ?
Thanks a lot !
Aymeric
If you have not otherwise specified, the files are only inside the one container filesystem, not at all on your host filesystem. The files are in your Windows file system only if you have used bind mounts when running your container and mapped host files/directories to container volume mounts.
In general Docker files can exist in three places:
layered container filesystem (default)
volumes (persistent volumes in your Docker host, volumes can be shared between multiple containers running on the same host)
bind mounts (files or directories in your Docker host filesystem)
You did not provide the actual docker run command you have used to run your Prestashop. This would reveal what option your setup is. More info on Dockker volumes can be found here: https://docs.docker.com/storage/
Which ever way you have stored the volume, you can use docker cp command to copy data between your container and host operating system.
Technically of course also the container filesystems and volumes are stored on your host disk but are not meant to be accessible directly. It is not recommended to access them directly and different versions of Docker have different restrictions. Some info on where to find it on Docker for Windows can be found from answers to this question: Locating data volumes in Docker Desktop (Windows)

name resolution between different docker hosts

I have 10 different host each host has many docker containers, which each few container managed by a docker-compose, containers within the docker-compose can communicate with each other, even containers with in the host can communicate with each other although they are from different docker-compose, but now I want to have ability to reach container which is hosted in different machine within the docker host, other than DNS is there any other way ?
docker-compose is supposed to work only within one host.
If you want your docker containers run on different hosts you should consider using Kubernetes or Docker swarm.

Mapping Docker Volumes in a Cluster/Docker-Swarm

I am running Docker Swarm with 3-Masters and 3-Worker nodes.
On this Swarm, I have an Elastic search container which reads data from multiple log files and then writes the data into a directory. Later it reads data from this directory and shows me the logs on a UI.
Now the problem is that I am running only 1 instance of this Elastic Search Container and say for some reason it goes down then docker swarm start this on another machine. Since I have 6 machines I have created the particular directory on all the machines, but whenever I start the docker stack the ES container starts and starts reading/writing directory on the machine where it is running.
Is there a way that we can
Force docker swarm to run a container on a particular machine
or
Map volume to shared/network drive
Both are available.
Force docker swarm to run a container on a particular machine
Add --constraint flag when executing docker service create. Some introduction.
Map volume to shared/network drive
Use docker volume with a driver that supports writing files to an external storage system like NFS or Amazon S3. More introduction.

How to assign separated volumes to each container? [Docker-swarm] [Hyperledger]

Generally, Hyperledger use an internal /var/hyperledger/ to store the database for each container. And we actually need to mount this directory outside of the container.
When running a bare command docker run or docker-compose, we can specify this parameter separately or even use the docker compose file.
Question:
Since I may need to try Hyperledger with the docker swarm (Docker 1.12), and each Hyperledger container must not uses the same shared volume with any others. So, how can I specify the separated volumes to each container using Docker swarm mode?
$ docker service create ...

Docker: mounting volumes from other docker service (not container)

I have two hosts that run docker service on each host.
Container from host A wanted to uses volume that created from host B.
Is this possible?
noops, both services should be on the same host but there is one thing you can do.
All reused data volumes are mounted on the same paths as in the source
service. Containers must be on the same host in order to share
volumes, so the containers of the new service will deploy to the same
nodes where the source service containers are deployed.
https://docs.docker.com/docker-cloud/apps/volumes/
Possible solution:
mount volume to a host directory
sync that directory between your nodes
You can use NFS to sync directories on all nodes, i have used it myself works fine

Resources