From my tutorial, it creates clone Dockerfile (Dockerfile2) and build the second Docker.
docker build . -f Dockerfile2 -t
But I don't understand what . does.
According to Docker documentation.:
-t : tag ...
-f : file...
What is this command doing? - Thanks
Obviously the tag is missing. Anyway you're telling Docker:
Hey Docker, the current directory is your build context so copy everything from this location (except the files and directories mentioned in the .dockerignore file) and build the image for me using the instructions from the Dockerfile2 file. Also, please tag it using the provided tag so I can reference it easily.
If you ommit the file (drop the -f argument), then the default Dockerfile file is assumed.
. means the current directory where you are. And the Dockerfile is in it. If you do not in the directory of the Dockerfile, you will get the error.
The full command : docker build path -f Dockfile -t containerName. Also the document docker build [OPTIONS] PATH | URL | -.
From the Docker build documentation:
Usage:
docker build [OPTIONS] PATH | URL | -
build: Build an image from a Dockerfile
.: Specifies that the PATH is ., and so all the files in the local directory get tar d and sent to the Docker daemon. The PATH specifies where to find the files for the “context” of the build on the Docker daemon.
--file , -f: Name of the Dockerfile (Default is ‘PATH/Dockerfile’).
--tag , -t: Name and optionally a tag in the ‘name:tag’ format. You can apply multiple tags to an image.
So, what is happening is: Docker I want to build an image from a Dockerfile called Dockerfile2 tagged with the value (you didn't set the value of the tag) in the current path.
Related
I am a Docker Beginner and I have some trouble with Dockerfile build..and a lot of questions
Do I have to start command build in path /var/lib/docker/builder ?
How do I know that it does not build because my Dockerfile is not correct written?
Do I have to call my folder Dockerfile?
docker build -t dokcerfile/xdebugphp .
than i got
Error response from daemon: unexpected error reading Dockerfile: read lstat /var/lib/docker/builder/Dokcerfile: no such file or directory
with
Get-Content Dockerfile | docker build -
Error response from daemon: the Dockerfile (Dockerfile) cannot be empty
You can launch docker build from any directory. If you try to COPY a file into an image that doesn't exist in the directory you name, you will see an error message that references /var/lib/docker, but that's an artifact of the Docker build implementation. (In fact, you really shouldn't look inside or try to directly use the /var/lib/docker directory at all.)
The file containing the build instructions is conventionally named Dockerfile (on systems with case-sensitive filesystems, with a capital D and no extension). It's most often located at the root of your source repository. This shouldn't be a directory.
The docker build -t option assigns a tag (name) to the image that's built. It doesn't have to correspond to a file on disk. If you're using Docker Hub to store your images (or just want to emulate its naming) these have the form username/imagename:version; there is an extended format if you're using some other Docker image registry.
You can name the Dockerfile something else; if you do, you need the docker build -f option to reference that file. If it's in a subdirectory of the repository root, the important detail is that COPY statements copy from the "context" directory you pass as the directory argument to docker build; this could be different from the directory that contains the Dockerfile. For example, if your Dockerfile has COPY index.php ., and you run docker build -f docker/xdebugphp ., the file is copied from the . current directory, which is the parent directory of the Dockerfile.
Looks like line endings, try changing dockerfile line endings to LF
Also for Docker build command you need to be in the directory where the dockerfile is or specify the path to the dockerfile
so in the directory where dockerfile is command is
docker build -t IMAGENAMEHERE .
So I solved it with this command
docker build -t imagename -f Dockerfile/xdebugphp .
Dockerfile is:
FROM nginx
COPY html /usr/share/nginx/html
Dockerfile is in pwd directory(which is home/ubuntu/app), when use following command:
docker build -t mynginx .
I was giving an error:
copy failed: stat /var/lib/docker/tmp/docker-builder344/html: no such file or directory.
how to change docker source of the context of the build?
Docker build only look files in Dockerfile file context, mean the build will copy /home/ubuntu/app/ from this location where your Dockerfile is.
So better to place your html the /home/ubuntu/app in this location as docker build send tar of the context to docker daemon so it is recommended to keep the context minimal.
docker build -t mynginx . would expect to find Dockerfile in the current directory. Moreover, relative paths used by Dockerfile instructions would be relative to the current directory.
You can set the build context path to a different path docker build -t mynginx [some_folder_path]. Docker would search for Dockerfile there. You can modify the path to Dockerfile using -f option docker build -f [path_to_dockerfile] -t mynginx [some_folder_path]
When building docker images with a Dockerfile in the same directory, the following works every time
$ docker build -t project/app:latest .
Sending build context to Docker daemon 135.9MB
...
However, when using -f to specify a different Dockerfile to use, docker complains ...
$ docker build -t project/app:latest -f ../some/path/Dockerfile.other
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
I can easily provide the PATH, and the build will work, but why is the PATH still required if I'm specifying the absolute path to the Dockerfile with -f?
The PATH is for specifying the build context (the tree from which COPY instructions copy things), which need not have any relation to the location of the Dockerfile.
Quoting the docs:
The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.
I've been trying to build syntaxnet on my ubuntu setup and bumped into a problem (simple as it may be) that I had hard time finding the solution to.
Whenever I try to build using the command:
docker build -t dragnn-oss:latest-minimal -f docker-devel/Dockerile.min
I get the error message:
"docker build" requires exactly 1 argument(s).
Now, my docker version is 17.06 and according to this page,
[docker: "build" requires 1 argument. See 'docker build --help', I should be able to specify a Dockerfile that is located in a different directory, so I don't see what the problem is.
Edit: I created a symlink by doing:
ln -s docker-devel/Dockerfile.min link1
Then I just went through with the command:
docker build -t dragnn-oss:latest-minimal -f link1 .
and it worked.
I thought I did not need to put the . at the end since I specified the Dockerfile with -f but learned the mistake.
You need to add a dot at the end, either
docker build -t mytag .
or
docker build -t dragnn-oss:latest-minimal -f docker-devel/Dockerile.min .
see also
docker: "build" requires 1 argument. See 'docker build --help'
While the other answers are all correct and you've found the solution, I want to point you to the documentation for docker build for anyone stumbling upon this. This is what the command is supposed to look like:
$ docker build [OPTIONS] PATH
In your example, you specified two options (-f and -t). But you didn't specify the PATH argument. Citing the documentation:
The PATH specifies where to find the files for the “context” of the build on the Docker daemon.
The context is sent to the Docker daemon when building an image. You can just use . if you want to use the correct directory as Docker's build context, but as others have mentioned, you can also specify a specific directory, e.g. docker-devel.
Specify a directory and in this directory, a Dockerfile :
docker build -t dragnn-oss:latest-minimal -f Dockerile.min docker-devel
You need to add an argument to the end with just the path.
If it's the current directory then . (simple dot) will suffice.
The -f param is just for the filename (Dockerfile being the default)
docker build -t dragnn-oss:latest-minimal -f Dockerile.min docker-devel
I can't seem to get docker build to run correctly:
wangyaos-MBP-3:~ wangyao$ cd /Users/wangyao/Ozintel/docker/flexcloud/
wangyaos-MBP-3:flexcloud wangyao$ ls
Dockerfile apache-tomcat-7.0.62 jdk1.8.0_45.jdk
wangyaos--3:flexcloud wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud" .
Invalid namespace name (Users). Only [a-z0-9-_] are allowed.
wangyaos-MBP-3:flexcloud wangyao$ cd /Users/wangyao/
wangyaos-MBP-3:~ wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud" .
Cannot locate Dockerfile: Dockerfile
wangyaos-MBP-3:~ wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud"
docker: "build" requires 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build a new image from the source code at PATH
How should I use docker build?
Slow down and take a look at the docs.
To use docker build, the easiest way is to cd into the directory with the Dockerfile then run something like:
$ docker build -t flexcloud .
The -t argument specifies the repository name and tag, not the directory with the Dockerfile. If you want to give a path to a different Dockerfile, you can use the -f argument. The . at the end specifies the "build context", in this case the current working directory.