Copy folder form Dockerfile to host

Hello all,
I have a docker file

FROM ubuntu:20.04
################################
### INSTALL Ubuntu build tools and prerequisites
################################
# Install build base

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
    build-essential \
    git \
    subversion \
    sharutils \
    vim \
    asciidoc \
    binutils \ 
    bison \
    flex \
    texinfo \
    gawk \
    help2man \
    intltool \
    libelf-dev \
    zlib1g-dev \
    libncurses5-dev \
    ncurses-term \
    libssl-dev \
    python2.7-dev \
    unzip \
    wget \
    rsync \
    gettext \
    xsltproc && \
    apt-get clean && rm -rf /var/lib/apt/lists/*
 
ARG  FORCE_UNSAFE_CONFIGURE=1
RUN  git clone https://git.openwrt.org/openwrt/openwrt.git
WORKDIR /openwrt
RUN ./scripts/feeds update -a && ./scripts/feeds install -a
COPY .config /openwrt/.config
RUN mkdir files
WORKDIR /files
RUN mkdir etc
WORKDIR /etc
RUN mkdir uci-defaults
WORKDIR /uci-defaults
COPY xx_custom /openwrt/files/etc/uci-defaults/xx_custom
WORKDIR /openwrt
RUN make -j 4
RUN ls /openwrt/bin/targets/ramips/mt76x8

WORKDIR /root
CMD ["bash"]

I want to copy all the files inside the folder mt76x8 to the host. I want to that inside the dockerfile so that when I run the docker file I should get the generated files in my host.

How can I do that?

Maybe you'd like to separate the Dockerfile into two procedures. One for docker build to only build a docker image. Then docker run to do the actual build at which time you can add -v host_path:container_path so that content generated inside container will appear in host_path and persist there after the container exits

2 Likes

I use https://git.laboratoryb.org/hurricos/docker-builder. for that I make sure when I run docker run, I:

  • mount ./input/ to /input
  • mount ./output/ to /output
  • my ENTRYPOINT is a script which runs "start by running /input/input.sh; then run your thing; then run /output/output.sh"
  • output.sh includes a step to copy the content of bin/ (OpenWrt buildsystem output) to /output/bin/.