Docker在构建过程中不创建目录 [英] Docker doesn't create directory during build

查看:86
本文介绍了Docker在构建过程中不创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首次使用Docker进行实验.在我的Dockerfile中执行以下步骤以创建目录,但是当我运行容器时,该目录不存在.

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

构建图片:

docker build -t ubuntu-ssh --no-cache .

运行容器时测试目录:

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

推荐答案

使用命名为 volume ,而不是绑定安装

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

这篇关于Docker在构建过程中不创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆