問題描述
如何在 docker 映像中創建目錄? (How can I make dir inside docker image?)
為什麼會出錯?
Dockerfile
FROM certbot/certbot
WORKDIR /
RUN mkdir ‑p /etc/letsencrypt/live
RUN cd /etc/letsencrypt/live
docker build ‑‑no‑cache .
/ bin/sh: cd: line 1: can't cd to /etc/letsencrypt/live: No such file or directory
參考解法
方法 1:
If you look at the Docker Hub certbot/certbot
page, click on "Tags", and select one of the tags, you can get an automated dump of the build sequence for the image. Of note, that contains a line
VOLUME [/etc/letsencrypt /var/lib/letsencrypt]
A directory that's marked as a VOLUME
in a Dockerfile can't be subsequently modified by RUN
commands, even in a derived image; changes will just be discarded.
方法 2:
As a workaround, you may try to add there an empty file from outside into that directory
ADD readme.txt /etc/letsencrypt/live/readme.txt
(by alexey2baranov、David Maze、lazylead)