P
P
Pavel2018-07-05 15:29:55
Docker
Pavel, 2018-07-05 15:29:55

How do they copy files from docker to the host when creating a container?

Dockerfile
FROM alpine:latest

ENV ROOT_DIRECTORY=/caddyserver
ENV CONF_DIRECTORY=/caddyserver/cfg
ENV WWW_DIRECTORY=/caddyserver/www
ENV LOGS_DIRECTORY=/caddyserver/logs

#ARG Plugins='http.cache,net,http.git,http.ipfilter'

VOLUME $CONF_DIRECTORY $WWW_DIRECTORY $LOGS_DIRECTORY

RUN apk add --no-cache openssh-client git

ENV Email=''
ENV CPU=''

EXPOSE 80 443 2015


CMD $ROOT_DIRECTORY/caddy -conf $ROOT_DIRECTORY/cfg/Caddyfile -log $ROOT_DIRECTORY/logs/caddy.log -cpu $CPU -email $EMAIL -agree

Described such a dockerfile, when you try to run the container crashes
docker create \
  --name=caddy \
  -v /opt/Docker/caddy/cfg:/caddyserver/cfg \
  -v /opt/Docker/caddy/www:/caddyserver/www \
  -v /opt/Docker/caddy/logs:/caddyserver/logs \
  -e [email protected] -e CPU=2 \
  -p 80:80 -p 443:443 -p 2015:2015 \
  caddy

In the logs, he writes that he cannot find the configuration file in the cfg folder. As far as I understand, this is due to the fact that I mount a folder from the host to the cfg section and it is empty. At the time of creating the docker container, with the COPY command, I copy the structure and the basic configuration is contained there. How can I make this configuration visible from the host on initial startup?
Well, i.e. there was an example with gitlab, when the container is first launched, it already puts data, logs from the container into the necessary folders (In my example, the log is written and visible from the host), and on subsequent launches it already mounts and uses them.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rustler2000, 2018-07-06
@rustler2000

No way.
More precisely, only if someone in the container overwrites them if there are no files.
And the standard mount behaves exactly the same - no magic "merge"

P
Pavel, 2018-07-06
@rusbaron

Because there is another subscriber to the question, I’ll add what I found
After ventilating this question, I came across the following, as done by linuxserver.io
Creating an image based on their alpine image ( which, by the way, you can pass PUID and GUID for files and folders with parameters ), the necessary configuration files we put it in the right folder (they usually do it in the defaults folder), then we create the 20-config file along the path /etc/cont-init.d/ and add the necessary conditions there

Example 20-config in my case
#!/usr/bin/with-contenv bash

# make folders
mkdir -p \
  /caddyserver/{cfg,logs,www}

# copy config
 && cp \
  /defaults/Caddyfile /caddyserver/cfg/Caddyfile


# permissions
chown -R abc:abc \
  /caddyserver

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question