How containerd copy a file from host to a running container? - docker

I find that I can use ctr snapshot mount to copy a file from a container to a host.
But how can I copy a file from a host to the container using containerd?
I used golang to write some code to start a container, but I can't find any documentation about copying host files to a running container.

As of now there is no provision as such with either with ctr or crictl cli to copy a host file to a running container as we have with docker cli (eg: docker cp).
Though there is a project under containerd known as nerdctl which is trying to emulate the same.
nerdctl is a Docker-compatible CLI for containerd.
Link for reference: Nerctl cp command

Related

Change mountpoint of docker volume to a custom directory

I would like to have a Docker Volume that mounts to a container. This volume would need to be somewhere other than the default location of volumes, preferably somewhere on the Desktop. This is because I am running a web server and would like some directories to be editable by something like VSCode so I don't always have to go inside the container to edit a file. I am not going to be using Docker Compose and instead will be using a Docker File for the container. The functionality I'm going for is the following equivalent of Docker Compose, but in a Dockerfile or through docker run, whichever is easiest to accomplish:
volumes:
- <local-dir>:<container-dir>
This directory will need to be editable LIVE and using the Dockerfile ADD command will not suffice, because after building, the image gets put into a tar archive and cannot be accessed after that.
with this solution you can move even A live container to new partition:
Add a configuration file to tell the docker daemon what is the location of the data directory
Using your preferred text editor add a file named daemon.json under the directory /etc/docker. The file should have this content:
{
"data-root": "/path/to/your/docker"
}
Copy the current data directory to the new one
sudo rsync -aP /var/lib/docker/ /path/to/your/docker
Rename the old docker directory
sudo mv /var/lib/docker /var/lib/docker.old
Restart the docker daemon
sudo service docker start
resource: https://www.guguweb.com/2019/02/07/how-to-move-docker-data-directory-to-another-location-on-ubuntu/
You can mount a directory from your host inside your container when you launch the docker container, using -v or --volume
docker run -v /path/to/desktop/some-dir:/container-dir/path <docker-image>
Volumes specified in the Dockerfile, as you exemplified, will automatically create those volumes under /var/lib/docker/volumes/ every time a container is launched from that image, but it is NOT recommended have these volumes altered by non-Docker processes.

Copy file from bamboo user/host to docker container

I am using docker task in my bamboo to build the project. To build the project I need to copy some file from bamboo user to the docker container.
We can copy a file from the host to the docker container by docker cp command but how can we do this in bamboo. I am not able to find any useful post. Anyone have any idea or a link to copy a file to docker in bamboo.
I am using run a docker container from image.
In case someone else having this issue --
I have used volumes to mount host/bamboo directory in the Docker container and then I can access the file in the Docker container ("Additional arguments" or "Volumes" section).

Run command on jenkins docker container to copy file to host

Is there a way to copy file from docker container to the host by running the command on the container itself?
I know that I can use "volume" but it will not work - I want to copy files from container to arbitrary places on the host.
Only SCP file vis SSH?
From: Copying files from Docker container to host you can run:
docker cp <containerId>:/file/path/within/container /host/path/target

how to configure Cassandra.yaml which is inside docker image of cassandra at /etc/cassandra/cassandra.yaml

I am trying to edit cassandra.yaml which is inside docker container at /etc/cassandra/cassandra.yaml, I can edit it from logging inside the container, but how can i do it from host?
Multiple ways to achieve this from host to container. You can simple use COPY or RUN in Dockerfile or with basic linux commands as sed, cat, etc. to place your configuration into the container. Another way you can pass environment variables while running your cassandra image which will pass those environment variables to the spawning container. Also, can use the docker volume mount it from host to container and you can map the configuration you want into the cassandra.yaml as shown below,
$ docker container run -v ~/home/MyWorkspace/cassandra.yaml:/etc/cassandra/cassandra.yaml your_cassandra_image_name
If you are using Docker Swarm then you can use Docker configs to externally store the configuration files(Even other external services can be used as etcd or consul). Hope this helps.
To edit cassandra.yaml :
1) Copy your file from your Docker container to your system
From command line :
docker ps
(To get your container id)
Then :
docker cp your_container_id:\etc\cassandra\cassandra.yaml C:\Users\your_destination
Once the file copied you should be able to see it in your_destination folder
2) Open it and make the changes you want
3) Copy your file back into your Docker container
docker cp C:\Users\your_destination\cassandra.yaml your_container_id:\etc\cassandra
4) Restart your container for the changes to be effective

How could I get files from a docker container running the official etcd image if there is no shell?

I have a docker container that is running the etcd docker image by CoreOS which can be found here: https://quay.io/repository/coreos/etcd. What I want to do is copy all the files that are saved in etcd's data directory locally. I tried to connect to the container using docker exec -it etcd /bin/sh but it seems like there is no shell (/bin/bash, /bin/sh) on there or at least it can't be found on the $PATH variable. How can I either get onto the image or get all the data files inside of etcd copied locally?
You can export the contents of an image easily:
docker export <CONTAINER ID> > /some_file.tar
Ideally you should use volumes so that all your data is stored outside the container. Then you can access those files like any other file.
Docker has the cp command for copying files between container and host:
docker cp <id>:/container/source /host/destination
You specify the container ID or name in the source, and you can flip the command round to copy from your host into the container:
docker cp /host/source <id>:/container/destination

Resources