jdesilvio
jdesilvio

Reputation: 1854

Docker persistent data linking

I am trying to create 3 container Docker environment:

I create the data-only and the database containers by running:

docker run -d -t --name dbdata -v /dbdata data-only

docker run -d -t --volumes-from dbdata --name db hdf5

I have tested for persistence between the data-only container and the database container and it works.

Linking the app container:

Here is where I am running into issues. When I link the app container to the database container running:

docker run -i -t -p 5000:5001 --link db:db --name app py-opencv

I cannot find my data-only volume /dbdata. I have read everything I can to figure out why, but to no avail.

When I run docker inspect app I can see the link:

"Links": [
            "/db:/app/db"
        ]

And I also see: "Mounts": [] and "VolumesFrom": null not sure if that is an issue.

When I run docker exec app cat /etc/hosts I see:

172.17.0.4  1cab4ab3c886
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2  db 5e291000ab13

Please help


Dockerfiles (with some of the guts stripped out for brevity):

data-only

FROM debian:jessie

ENV HOME /root

CMD ["true"]

database

FROM debian:jessie

ENV HOME /root

# Install dependencies via apt-get
# Build HDF5
# Cleanup

EXPOSE 5001

app

FROM python:3.5

ENV HOME /root

# Install dependencies
# Install Python packages
# Build OpenCV and dependencies

# Update environment and directories
ENV PYTHONUNBUFFERED 1
ENV HDF5_DIR /usr/bin/ld
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/

EXPOSE 5000

Upvotes: 1

Views: 164

Answers (1)

Vaidas Lungis
Vaidas Lungis

Reputation: 1541

Your data container is only in db container as you run command docker run -d -t --volumes-from dbdata --name db hdf5

if you want to get access to that data container in your app container you should also add command volumes-from

with this command docker run -i -t -p 5000:5001 --link db:db --name app py-opencv you only linking two containers. app container get a /etc/hosts configuration about db container but not about data volume.

so instead of docker inspect app run docker inspect db and you will find your data container information in mount parameter

Upvotes: 1

Related Questions