1

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?

2 Answers2

0

you can use the volume mount to access the docker-generated artifacts on the host machine.

you can also run the command

docker cp to copy the files to the host machine.

if don't want to use the docker command as mention only option is to use the volume.

you can also use docker create once the docker image is ready to create the writable layer and copy data.

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • Copying files from a docker *image* vs. a running container are different things. The solutions posted by others copy files from a container. To copy a directory from an image, you can use the `tar` command: `docker run --rm --entrypoint tar MY_IMAGE_NAME czf - /path/to/mydir/inside/the/image > mydir.tar.gz` and then `tar xzf mydir.tar.gz -C /host/path/to/mydir` – user553965 Jul 23 '23 at 15:04
  • Thanks for sharing would suggested checking out Docker create once, without running actual container you can do same copy paste files – Harsh Manvar Jul 23 '23 at 15:18
0

You have two choices.

  1. Use docker volumes to map the /openwrt/bin/targets/ramips/mt76x8 folder when you are running the container. i.e. docker run -v {VoluneName}:/openwrt/bin/targets/ramips/mt76x8. All of the files in the mt76x8 folder would be available in the volume folder. If you are using Linux then you will find the docker volumes in /var/lib/docker/volumes/
  2. You can use docker cp command to copy data from container to the host machine. Here is an example
Aak
  • 269
  • 4
  • 16