I trying copy a folder to my container but not working. If I try
sudo docker cp 4aefd670e41f:/var/www/html/web2015 /home/desarrollo3/proyectos/web2015
The folder web2015 copy correct but I need copy the folder in my container.
Working ok
sudo docker cp 4aefd670e41f:/var/www/html/web2015 /home/desarrollo3/proyectos/web2015
Not Working
sudo docker cp /home/desarrollo3/proyectos/web2015 4aefd670e41f:/var/www/html/web2015
Aditional info Docker
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.3.3
Git commit (client): 7c8fca2
OS/Arch (client): linux/amd64
Server version: 1.6.2
Server API version: 1.18
Go version (server): go1.3.3
Git commit (server): 7c8fca2
OS/Arch (server): linux/amd64
I've Ubuntu 15
The error FATA[0000] Error: Path not specified
sudo docker cp /home/desarrollo3/proyectos/web2015 4aefd670e41f:/var/www/html/web2015
If I write this, I don't get errors but not copy nothing:
sudo docker cp ./folder:web2015 4aefd670e41f:/var/www/html/
If it is a folder that you need to copy, make sure SRC_PATH ends with / (considering DEST_PATH on the container does exist already)
sudo docker cp /home/desarrollo3/proyectos/web2015/ 4aefd670e41f:/var/www/html/web2015
docker cp mentions:
SRC_PATH does end with /.
the content of the source directory is copied into this directory.
As shown in issue 13171, the error message "Error: Path not specified" was fixed in docker 1.8.0 (commit 5e86b81).
Docker 1.6.2 is way too old.
You can't copy to a container using "docker cp" in older dockers. If you desperately need to do it for whatever reason:
docker exec container touch /myfile
sudo find /var/lib/docker -iname myfile
This will show you where the your container filesystem is. Just cp your file here normally.
sudo cp -r /myfiles/webapp /var/lib/docker/aufs/mnt/019283091823081027401720473a2c7ff637a6f09edab6/var/www/localhost/htdocs
I'm not sure why Docker doesn't officially actually do this, but I suspect that there is some checksum on each layer, so if you re-use the image in another Dockerfile it might not work. But it should at least work for the lifetime of the container, so you can do what you need to.
Which hopefully for you includes updating or replacing this server soon.
Related
There is a previous question (Docker Unknown flag --mount) facing the same error that was due to having an out-of-date version of Docker running. I have an up-to-date version of Docker running.
I have the following Dockerfile:
FROM continuumio/miniconda3
RUN --mount=type=ssh pip install git+ssh://git#github.com/myrepo/myproject.git#develop
RUN conda install numpy
...
According to the documentation, I should be able to simply run docker build --ssh default .. However, I receive the following error:
Sending build context to Docker daemon 2.048kB
Error response from daemon: Dockerfile parse error line 3: Unknown flag: mount
Output of docker version:
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:39 2019
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: true
I would like to build a Docker image without exposing my private SSH credentials, and this seemed to be the supported method. Anyone have thoughts on what's causing the issue?
tl;dr
Dockerfile
# syntax=docker/dockerfile:experimental
FROM continuumio/miniconda3
RUN --mount=type=ssh pip install git+ssh://git#github.com/myrepo/myproject.git#develop
RUN conda install numpy
...
Note: the comment on the first line is required voodoo
Then build your docker image with:
DOCKER_BUILDKIT=1 docker build --ssh default -t my_image .
With this, you will be able to use the --mount option for the RUN directive in your Dockerfile.
Long answer
As found in the documentation here, ssh forwarding when building docker image is enabled only when using the BuildKit backend:
External implementation features
This feature is only available when using the
BuildKit
backend.
Docker build supports experimental features like cache mounts, build
secrets and ssh forwarding that are enabled by using an external
implementation of the builder with a syntax directive. To learn about
these features, refer to the documentation in BuildKit
repository.
For this you need Docker 18.09 (or later) and you also need to run the docker build command with the DOCKER_BUILDKIT=1 environment variable and start your Docker file with the following magic comment : # syntax=docker/dockerfile:experimental.
Also you can edit /etc/docker/daemon.json and add :
{
"experimental" : false,
"debug" : true,
"features": {
"buildkit" : true
}
}
If you are using sudo for docker commands, you might need:
sudo DOCKER_BUILDKIT=1 ...
To anyone out there that might be struggling with this sort of error: ensure that the first line of the file is '# syntax=docker/dockerfile:experimental'. This will work:
# syntax=docker/dockerfile:experimental
FROM golang:1.14.1 as builder
...
RUN --mount=type=ssh GOSUMDB=off go get -d -v ./...
BUT if you add a comment at the start of the file like so:
# SOME SILLY COMMENT HERE <--- this ostensibly innocent comment ruins everything!
# syntax=docker/dockerfile:experimental
FROM golang:1.14.1 as builder
...
RUN --mount=type=ssh GOSUMDB=off go get -d -v ./...
Then 'syntax=...' will not be taken into account because it's no longer on the very first line. This is why you get that weird error about 'mount' below! Gah!
Hopefully this will save a few hours from the lives of a few people.
The error message that you are getting due to writing --mount inside the Dockerfile. You have to enable Docker BuildKit first in order to use this syntax.
You can check all of the currently available build options through here
Locally I just needed DOCKER_BUILDKIT=1 docker build...
In TeamCity build pipeline my docker file still needed the magic line to overcome this issue. My TeamCity agent is running Docker version 19.03.9
So in 2022 this is still my conclusion:
Try the magic line mentioned at the top of your Docker file:
#syntax=docker/dockerfile:experimental
Use BUILDKIT. e.g. DOCKER_BUILDKIT=1
.. and in my context this is all for running the following line:
RUN --mount=type=ssh npm install "git+ssh://git#github.com:dra_____.git"
Maybe this will save some folks some time.
I have a Dockerfile:
FROM jpetazzo/dind
ENV debian_frontend noninteractive
RUN apt-get -y update
RUN apt-get install -y supervisor
COPY supervisor.conf /etc/supervisor.conf
COPY wrapdocker.conf /etc/supervisor/conf.d/wrapdocker.conf
CMD supervisord -c /etc/supervisor.conf
Running it gives me an EOF:
$docker build .
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon
Step 0 : FROM jpetazzo/dind
EOF
I am on Ubuntu 14.04:
$docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64
Any clue why is there an EOF?
I tried to re-copy the file in another directory, it didn't change anything. Changing FROM jpetazzo/dind to FROM ubuntu does change things.
EDIT:
The logs created during the mistake:
/var/log/upstart$ sudo cat docker.log
INFO[0568] POST /v1.19/build?cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&memory=0&memswap=0&rm=1&t=
I tried to re-produce that error by using your Dockerfile without success:
$ docker build .
Sending build context to Docker daemon 4.608 kB
Sending build context to Docker daemon
Step 0 : FROM jpetazzo/dind
---> e82a08f5b4e3
Step 1 : ENV debian_frontend noninteractive
---> Running in bb205a0e8238
---> e1e5993a94b7
Removing intermediate container bb205a0e8238
Step 2 : RUN apt-get -y update
---> Running in 1004dda4c147
Get:1 https://get.docker.com docker InRelease
Ign https://get.docker.com docker InRelease
Hit https://get.docker.com docker Release.gpg
Hit https://get.docker.com docker Release
...
Are you sure that you do not have networking issues on the host where your Docker daemon runs?
I am using the same Docker server/client version like you.
I am trying to copy a single file from the root of the build context into a newly created directory in a docker image.
The Dockerfile that I am using is as follows:
FROM debian:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY test.txt /usr/src/app
The test.txt file is a simple ASCII text file as follows:
$ cat test.txt
This is a test
However, when I build this image I get an image stating that the destination path is not a directory.
$ docker build .
Sending build context to Docker daemon 4.608 kB
Sending build context to Docker daemon
Step 0 : FROM debian:latest
---> 9a61b6b1315e
Step 1 : RUN mkdir -p /usr/src/app
---> Using cache
---> 86bd44a8776e
Step 2 : WORKDIR /usr/src/app
---> Using cache
---> ed6771adc681
Step 3 : ADD test.txt /usr/src/app
stat /var/lib/docker/devicemapper/mnt/ee5b9b7029f2adf27d332cbb0d98d6ad9927629a7569fd2d9574cb767b23547b/rootfs/usr/src/app/test.txt: not a directory
I have tried using multiple combinations of docker versions, base images, and distributions with docker installed. I have also tried using ADD instead of COPY but the result is the same.
I am currently trying this on CentOS 7 with the following docker version installed:
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64
What I have noticed is that I can copy a directory, but not a file. For example, if I create a "test" directory in the build context root and put test.txt inside the test directory then I can copy the directory successfully:
FROM debian:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY test /usr/src/app
Note that in the above Dockerfile I copy the entire ./test directory rather than just ./test.txt. This build successfully.
The Docker documentation has the following sample use case for the COPY instruction which is similar to what I am trying to do:
COPY hom?.txt /mydir/
Can anyone point out what I am doing wrong? How can I go about copying a single file?
As stated in the Dockerfile documentation:
If <src> is any other kind of file, it is copied individually along with its metadata. In this case, if <dest> ends with a trailing slash /, it will be considered a directory and the contents of <src> will be written at <dest>/base(<src>).
If <dest> does not end with a trailing slash, it will be considered a regular file and the contents of <src> will be written at <dest>.
Thus, you have to write COPY test.txt /usr/src/app/ with a trailing /.
For me, I was adding a path based on the docker-compose.yml instead of the Dockerfile:
File structure
.
..
/docker-compose.yml
/docker/
/docker/php/
/docker/php/Dockerfile
/docker/php/my_file
and in / I was running docker-compose up --build.
instead of COPY docker/php/my_file /some/location I needed to run COPY my_file /some/location
I have found a strange difference between building docker images in my Ubuntu 14.04 host machine and the Docker Hub automated builds.
This is my Dockerfile:
FROM buildpack-deps:wheezy-scm
RUN echo $HOME
This is the output in my machine:
---> 2afbec25f6f6
Step 1 : RUN echo $HOME
---> Running in 6074455e13c0
/
---> 0cb1b6141f93
Removing intermediate container 6074455e13c0
Successfully built 0cb1b6141f93
And this one comes from Docker hub:
---> 2afbec25f6f6
Step 1 : RUN echo $HOME
/root
---> 4c781d2d7d72
Successfully built 4c781d2d7d72
Note the different HOME directories: /root instead of /. Can anyone explain me what is happening?
This is my Docker version (I have installed the standarddocker.io Ubuntu package):
$ docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.2.1
Git commit (client): 990021a
Server version: 1.0.1
Server API version: 1.12
Go version (server): go1.2.1
Git commit (server): 990021a
Effectively there were a change in $HOME, and the changes were merged after Docker release v1.0. I have built the Dockerfile you provided and it shows me $HOME=/root (I use Docker v1.5.0). Check Docker Issue #2968 and related commits for additional details.
My machine debian VM. It is not having boot2docker.
Docker was installed in it. I somehow updated docker.It is now giving me error of client and server of not same version.
by running "docker version" gives me this
Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8
OS/Arch (client): linux/amd64
FATA[0000] Error response from daemon: client and server don't have same version (client : 1.16, server: 1.15)
Thanks in advance.
If you do not have images or containers you wish to keep, remove and install again the latest docker version, with sudo apt-get remove lxc-docker && sudo apt-get purge lxc-docker && sudo apt-get install lxc-docker
One way to deal with this is dvm, the Docker Version Manager.
Clone it to, e.g. ~/.dvm:
git clone https://github.com/rgbkrk/dvm.git ~/.dvm
Then you need to source it directly or place it in your bash profile:
. ~/.dvm/dvm.sh
After this, install the version of docker you need:
$ dvm install 1.6.1
######################################################################## 100.0%
Now using Docker 1.6.1
You can swap between versions through dvm use VERSION:
$ dvm use 1.8.2
Now using Docker 1.8.2