Well without more details, here is how I would do it.
The containers have to run on the same Docker node.
Create a docker volume
🐳 gforghetti:[~] $ docker volume create my_binary_data
my_binary_data
Display the volume information
🐳 gforghetti:[~] $ docker volume ls
DRIVER VOLUME NAME
local my_binary_data
🐳 gforghetti:[~] $ docker volume inspect my_binary_data
[
{
"CreatedAt": "2019-02-11T15:12:50Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/my_binary_data/_data",
"Name": "my_binary_data",
"Options": {},
"Scope": "local"
}
]
Run a container and do a bind mount to the volume and bring up a shell inside the container.
🐳 gforghetti:[~] $ docker container run -it --name my-app1 --volume my_binary_data:/home/dev/tmp alpine:latest sh
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
6c40cc604d8e: Pull complete
Digest: sha256:b3dbf31b77fd99d9c08f780ce6f5282aba076d70a513a8be859d8d3a4d0c92b8
Status: Downloaded newer image for alpine:latest
/ #
Display the mounted file system on the volume.
/ # ls -la /home/dev/tmp/
total 8
drwxr-xr-x 2 root root 4096 Feb 11 15:12 .
drwxr-xr-x 3 root root 4096 Feb 11 15:13 ..
/ #
Create a file and put some data in it
/ # echo -e "Some binary data\nSome more binary data" > /home/dev/tmp/my-binary-data-file
/ #
Display the contents of the file
/ # cat /home/dev/tmp/my-binary-data-file
Some binary data
Some more binary data
/ #
Bring up another container and share the same volume.
🐳 gforghetti:[~] $ docker container run -it --name my-app2 --volume my_binary_data:/home/dev/tmp alpine:latest sh
/#
Access the file created by the 1st container my-app1
/ # cat /home/dev/tmp/my-binary-data-file
Some binary data
Some more binary data
/ #
Bring down both containers and remove them.
🐳 gforghetti:[~] $ docker container rm -f my-app1
my-app1
🐳 gforghetti:[~] $ docker container rm -f my-app2
my-app2
🐳 gforghetti:[~] $ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
🐳 gforghetti:[~] $
Bring up a new container and access the volume
$ docker container run -it --name my-app3 --volume my_binary_data:/home/dev/tmp alpine:latest cat /home/dev/tmp/my-binary-data-file
Some binary data
Some more binary data
/ #
The volume persists on the Docker node until your remove it.