docker container volumes from directory access in CMD instruction
Question
docker container volumes from directory access in CMD instruction
$ sudo docker run -d --name ext -v /external busybox /bin/sh
and
run.sh
#!/bin/bash
if [[ -f "/external" ]]
then
echo 'success!'
else
echo 'Sorry, I can't find /external...'
fi
and
Dockerfile
FROM ubuntu:14.04
MAINTAINER newbie
ADD run.sh /run.sh
RUN chmod +x /run.sh
CMD ["bash", "/run.sh"]
and
$ sudo docker build -t app .
and
$ sudo docker run -d --volumes-from ext app
ac57afb95f923eeffd28e7d9d9cb76cb1b7699ebd
So
$ sudo docker logs ac57afb95f923eeffd28e7d9d9cb76cb1b7699ebd
Sorry, I can't find /external...
My question is,
How can I access /external
directory in run.sh
in CMD
instruction
impossible?
Thank you~
Solution
modify your run.sh
-f
is check for file exists. in this case use -d
check for directory exists.
Check if a directory exists in a shell script
futhermore if you want make only volume container, need not add -d
, /bin/sh
volume container run command change like this
$ sudo docker run --name ext -v /external busybox