How to Copy Files From Docker Ubuntu Container to Windows Host - docker

I can't figure out how to copy files from a docker ubuntu container to a windows host, or vice versa.
My host is Windows 10. When I start Docker, I run the Ubuntu image using
docker run -it ubuntu bash
The documentation I've read says that the way the transfer files is with docker cp, but apparently that command doesn't exist in this ubuntu image, i.e., bash: docker: command not found.
This must be a dumb oversight on my part. Can someone please give me a little help?

You need to run docker cp command on host machine.
The command template is:
docker cp <containerId>:<src_path_inside_container> <target_host_path>

Related

Mounted Docker Volumes Are Empty

Problem
The $(pwd)/app directory locally contains many subdirectories and files. So does the directory in my Docker image /usr/local/app. When I run the following
docker run -it --rm -v $(pwd)/app:/usr/local/app my_image bash
the command is successful, but the /usr/local/app directory is now empty. It seems that I've mounted something to this location, but it's empty.
Is there something that I'm missing here that I should be aware of?
Context
This exact command used to succeed. The only recent change is that I uninstalled Docker Desktop in favor of just using the Docker Engine running on a local minikube instance. I'm using Docker version 20.10.22, build 3a2c30b63a on MacOS Ventura.

using local folder into docker container

Hi I have a windows machine and I installed a docker desktop on it and created a ubuntu container on it.
In docker settings I checked my C: Drive under shared drive option. and I created a folder under /opt named /mydata in this container
Now I run this command:
docker my_container_name run -v /Users/john/Documents/DOCKER_FOLDER:/opt/mydata
But I don't see the files under DOCKER_FOLDER to be in /opt/mydata folder.
Not sure what I a doing wrong.
the right command is:
docker my_container_name run -v c:/Users/john/Documents/DOCKER_FOLDER:/opt/mydata ls /opt/mydata
so you need to specify the volume letter and a command to run

Missing .docker folder on Ubuntu

I followed the official guide and installed docker-ce on Ubuntu 18.04 x64.
Per the instructions on Manage Docker as a non-root user, I tried to modify the ownership of .docker folder, and got a "No such file or directory" error:
$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
chown: cannot access '/home/eric/.docker': No such file or directory
In fact, I don't even have a .docker folder:
$ ls ~/.docker
ls: cannot access '/home/eric/.docker': No such file or directory
In an earlier step, I was able to run the hello-world container successfully:
$ sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
What did I do wrong?
Having the same problem. It finally worked for me after I restarted my laptop (which is running Ubuntu 18.04). Logging out and back in wasn't enough.
Manually created the .docker folder using mkdir .docker before restarting though.
The directory .docker (and the file .docker/config.json) will be created when you successfully authenticate to a Docker registry e.g Docker Hub running the command docker login.
(This presupposes $USER is part of the group docker.)

Docker not mapping folders

I am connected in a Docker container. In this container, when I execute:
sudo docker run --entrypoint bash -it -v /home/jenkins/workspace/deployment:/app myregistry.com/ansible-shade:2.2.1.0
I can see mapping is not happening between /home/jenkins/workspace/deployment and /app
In /home/jenkins/workspace/deployment, there is a lot of files, but in /app, I can't see anything
Any idea why does it happen ?
I found out what the problem,
My use case is that I work in a centOS that has all files, then I ssh a ubuntu that has no file and then in this ubuntu, I connect to docker container, so source path is from ubuntu not the docker image ( where files are )
The solution in that case is having files in the ubuntu vm so it can be mounted

Boot2Docker starting Ubuntu image

I am trying to get the latest Ubuntu image going om my Windows 7/Boot2Docker machine but when i try to start the image i get an error message.
exec: "C:/Program Files (x86)/Git/bin/bash": stat C:/Program Files (x86)/Git/bin/bash: no such file or directory
Full errormessage:
$ docker run -t -i ubuntu /bin/bash
exec: "C:/Program Files (x86)/Git/bin/bash": stat C:/Program Files (x86)/Git/bin/bash: no such file or directory
FATA[0000] Error response from daemon: Cannot start container 100e77a5ac95f8fb8dc55e6382e7a8cd6f946ec807e90d9efdb6fc905a046569: [8] System error: exec: "C:/Program Files (x86)/Git/bin/bash": stat C:/P
rogram Files (x86)/Git/bin/bash: no such file or directory
Any clue on how to work around this? Another image like the default Jenkins one works ok!
The Ubuntu image is pulled correctly
Running Ubuntu image after SSH:
docker#boot2docker:~$ docker run ubuntu
docker#boot2docker:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
It means that somehow your $PATH (within the boot2docker session) includes "C:/Program Files (x86)/Git/bin/" before /bin.
Check the $PATH you have when running docker run --rm -it ubuntu:latest.
The fact that you manage to run the image in a boot2docker ssh session, but docker ps displays nothing seems expected.
Only a docker run --rm -it ubuntu would display a shell.
A simplt docker run would exit the shell immadiatly (non-interactive run), and the container would be in status 'Exited' (see docker ps -a output)
First of all, before you create a container, you have to run "Boot2Docker Start" to start docker virtual machine then start your container inside docker VM. follow up the instructions in this link https://docs.docker.com/installation/windows/
Second, I think that it is preferred to install docker over linux machine not windows, you will get all capabilities of docker.
Best Regards,
Ahmed

Resources