Methods to Copy Information from Docker Container to Host

If it’s essential copy information from a Docker Container to the Host, then you are able to do one of many following:

Choice 1 – Utilizing docker cp#

Syntax:

docker cp [OPTIONS] CONTAINER: SRC_PATH DEST_PATH

Setup the container:

# pull the ubuntu picture
docker pull ubuntu

# run the container regionally
docker run -it -d ubuntu

# hook up with the container
docker exec -it abcde123456 /bin/bash

Create a file from the container:

cd usr
cd share
contact some_file.txt
ls

Copy the file from the container to the host:

docker cp abcde123456:/usr/share/some_file.txt ./some_file.txt
ls

Choice 2 – Utilizing Docker Mounts#

Syntax:

docker run -ti -v <host_directory>:<container_directory>

Carry out the copy:

docker run -it -v $HOME/listing/some_container:/some_container --name some_container ruby bash

Choice 3 – Utilizing COPY within the Dockerfile#

Syntax:

COPY <SRC> <DEST>

Create a Dockerfile with the COPY syntax:

FROM python

WORKDIR /var/www/

# Copy any sources required
COPY ./app.py /var/www/app.py
COPY ./necessities.txt /var/www/necessities.txt

RUN pip set up -r /var/www/necessities.txt

ENTRYPOINT ["echo", "Hello from the container"]