Please go through offical documentation properly.
Also check this out.
In your case this should work.
docker cp ex.txt my_container:/my_folder/
Update-1:
In your case, I doubt /my_folder
is not present inside the container, this is what the error says.
Also quoting the line mentioned in official documentation.
docker cp does not create parent directories for DEST_PATH if they do
not exist.
So the /my_folder
directory will not get created automatically.
Do this. docker exec -it my_container mkdir /my_folder
and then run docker cp command.
Update-2:
If nothing is working then please try this, it worked for me.
$ cat /root/ex.txt
abc
$ docker run -itd alpine sh
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
921b31ab772b: Pull complete
Digest: sha256:ca1c944a4f8486a153024d9965aafbe24f5723c1d5c02f4964c045a16d19dc54
Status: Downloaded newer image for alpine:latest
35ad53b81c30f675b28a53e6a266f039cf49e90705d41e499deb4f17ab900255
$
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35ad53b81c30 alpine "sh" 3 seconds ago Up 2 seconds mystifying_babbage
$
$ docker exec -it 35ad53b81c30 sh
/ # ls
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
/ # mkdir /my_folder
$
$ docker cp /root/ex.txt mystifying_babbage:/my_folder/
$
$ docker exec -it 35ad53b81c30 sh
/ # ls /my_folder/
ex.txt
/ # cat /my_folder/ex.txt
abc
/ #
Hope this helps.