3

I use OS X 10.13.3, and my docker version as follow:

Client:
 Version:   17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    c97c6d6
 Built: Wed Dec 27 20:03:51 2017
 OS/Arch:   darwin/amd64

Server:
 Engine:
  Version:  17.12.0-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.9.2
  Git commit:   c97c6d6
  Built:    Wed Dec 27 20:12:29 2017
  OS/Arch:  linux/amd64
  Experimental: true

I know docker is running in a vm on OS X, and I can get in by following command:

screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty

In docker's history version, docker use Docker.qcow2 as the image of vm. Local /Users direcotry is mounted into the docker vm, so I can copy a file to my home directory, such as /Users/username/Downloads:

cp /var/lib/docker/image/overlay2/repositories.json /Users/username/Downloads

In latest version, Docker use Docker.raw as the image of vm, and I can't copy file in that way.

How can I copy file from the vm to my OS X?

pkamb
  • 33,281
  • 23
  • 160
  • 191
lutaoact
  • 4,149
  • 6
  • 29
  • 41
  • It's not clear to me what you are asking, do you want to copy files from a Docker container to the Docker host? – Alessandro Cosentino Feb 04 '18 at 19:17
  • 1
    @lutaoact if you look at the answer to this question it should give you all of the information that you need: https://stackoverflow.com/questions/22907231/copying-files-from-host-to-docker-container. Ask if there's anything more specific that you need. – Geoff Feb 04 '18 at 20:44

2 Answers2

0

It can be done by using docker cp

docker cp <CONTAINER_ID>:<SRC_PATH_ON_CONTAINER> <DEST_PATH_ON_LOCAL_MACHINE>

More details: Docker docs

dtotopus
  • 562
  • 4
  • 5
  • 2
    A more clear explanation on how to use the command (maybe with an example) would help increase the value of this answer. As it stands right now, it's more likely seen as a comment. – geisterfurz007 Mar 06 '19 at 19:08
0

A possible workaround:

Add a local directory as a volume(bind-mount) for a container. In docker-compose.yml this would be like:

volumes:
       - wpdb:/var/lib/mysql 
       - ./db:/root 

wpdb is a docker volume would be inside the linux vm and inaccessible from the local mac directory

./db would be a bind-mount and accessible in the same directory as your docker-compose.yml file

Any file you copy into the /root directory would be available in your local mac directory ./db.

In the example above:

- ./db:/root 

would be a bind-mount.

This article may explain it more clearly:

Choosing Between Volume & Bind Mount

docker run -v $PWD:/home containername

stormwild
  • 2,855
  • 2
  • 31
  • 38