Reputation: 1850
Experimenting with Docker for the first time. Have these steps in my Dockerfile to create a directory, but when I run the container, the directory isn't there.
FROM ubuntu
MAINTAINER AfterWorkGuinness
RUN apt-get update
RUN apt-get install -y openssh-server
RUN mkdir /root/.ssh
RUN cd /root/.ssh
RUN ssh-keygen -t rsa -N "" -f id_rsa
VOLUME /root
EXPOSE 22
Build image:
docker build -t ubuntu-ssh --no-cache .
Testing the directory when I run the container:
docker run -it -v c:/users/awg/dev/tmp/home:/root ubuntu-ssh
root@39eec8fa51ad:/# cd ~/.ssh
bash: cd: /root/.ssh: No such file or directory
root@39eec8fa51ad:/# cd /root/.ssh
bash: cd: /root/.ssh: No such file or directory
Upvotes: 5
Views: 3608
Reputation: 74680
Use a named volume instead of a bind mount,
docker run -v tmphome:/root whatever
In a named volume the files will still persist over container restarts but the contents from the directory will be copied to the mounted volume at creation time. Docker chooses where to store the data depending on the driver in use. local
is the default and data defaults to the volume
directory in the Docker data dir, usually /var/lib/docker/volumes
Upvotes: 2