\Dockerfile: The system cannot find the file specified - docker

I have created a docker file to use node.js and nginx. When I run docker -t build <my docker file name> . I get the following error:
Dockerfile: The system cannot find the file specified.
Then in the docker file directory I created a folder name web and place my index.html and style.css file in it.
Question is: Any idea why I am getting this error?

The command docker -t build <my docker file name> . is being misused. It should be:
docker build -t <image-name> -f dockerFile .
where dockerFile is the name you gave to the Dockerfile.
The -t option specifies the tag or name to give to the Docker image.
The -f must be used, if you name the Dockerfile something other than Dockerfile
The . specifies the docker build context.

Related

Is it possible to create a docker image that just contains non executable files copied from host?

Is it possible to create an image of the contents of a folder on host. And later extract the content from image to the machine?
If so how?
Here is my failed attempt:
Dockerfile
WORKDIR '/data'
COPY ./hostfolder .
Command executed:
docker build -t mydata .
Folder structure:
Error:
Sending build context to Docker daemon 3.584kB
Error response from daemon: No build stage in current context
Yes, you can use a docker image as a place to store and then extract files.
First, you are missing a FROM directive in your Dockerfile. This is the reason for your error:
FROM alpine
WORKDIR '/data'
COPY . .
Then, to build the image:
$ docker build -t temp .
Then, to extract files, start the container:
$ docker run --detach --name data temp
and copy from the container to the host:
$ docker cp data:/data ./result

Why isn't docker recognizing my "-f" option?

Following this post -- docker: "build" requires 1 argument. See 'docker build --help', I'm trying to build my docker image using a file with a non-traditional name ("local.Dockerfile") on Mac 10.13.6. I tried the below
localhost:mydir davea$ docker build -t mycontainer -f local.Dockerfile
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
But docker is choking on me. I'm running version 19.03.5.
Basic command to build docker image:
docker build -t <image_tag> -f <Dockerfile_name> <Path_of_Dockerfile>
So you are missing to specify the path of your local.Dockerfile (which is mandatory). If your dockerfile is in the current directory from where you are running the command, then run below command, else update the path accordingly:
docker build -t mycontainer -f local.Dockerfile .
Note: You can specify the Path_of_Dockerfile in any way: relative path or absolute path, whichever way you feel comfortable.

How to run a private Docker image

docker run -i -t testing bash
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown.
I created the image in Docker Hub , it is private image.
FROM scratch
# Set the working directory to /app
WORKDIR Desktop
ADD . /Dockerfile
RUN ./Dockerfile
EXPOSE 8085
ENV NAME testing
This is in my Dockerfile
I tired to run it, when i run docker images i am getting the details
I think you need to do login in command prompt.useing below command.
docker login -u username -p password url
Apart from the login which should not cause these, as you build an image on your local system which I assume it should exist on local system which will only pull image if not exist on local, the real reason is you are building an image from scratch and there are no binaries in scratch image, even no bash or sh.
Second mistake:
RUN ./Dockerfile
Your Dockerfile is a file, not binaries, while here you are trying to execute using RUN directive.
While scratch appears in Docker’s repository on the hub, you can’t
pull it, run it, or tag any image with the name scratch. Instead, you
can refer to it in your Dockerfile. For example, to create a minimal
container using scratch:
FROM scratch
COPY hello /
CMD ["/hello"]
While here hello can be an executable file such as a C++ compiled file.
Docker scratch image
But what I would suggest to say "hello" in Docker is to use Busybox or Alpine as a base image which has a shell and both are under 5MB.
FROM busybox
CMD ["echo","hello Docker!"]
now build and run
docker build -t hello-docker .
docker run --rm -it hello-docker

How to add the file in docker

I am new to docker, I installed docker as per the instructions provided in the official site.
# build docker images
docker build -t iky_backend:2.0.0 .
docker build -t iky_gateway:2.0.0 frontend/.
Now, while I am running these commands in the terminal after the installation of docker, I am getting the below error. I tried with by adding sudo also. But no use.
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/esh/Dockerfile: no such file or directory
Your docker images should execute just fine (may require sudo if you are unable to connect to docker daemon).
docker build requires a Dockerfile to present at the same directory (you are executing at your home folder - dont do that) or you need to use -f to specify the path instead of .
Try this:
mkdir build
cd build
create your Dockerfile here.
docker build -t iky_backend:2.0.0 .
docker images

Create container from local file

I have a file called Dockerfile which contains a Docker configuration.
If I try to build a container from the file:
docker build Dockerfile
I get:
unable to prepare context: context must be a directory: C:\Path\To\Dockerfile
So how can I create a Docker container from a local configuration file?
According to https://docs.docker.com/engine/reference/commandline/build/ the parameter to docker build is not the Dockerfile, but a directory or URL containing the Dockerfile. So your command should rather be
docker build .
or even better, considering docker defaults to the current dir:
docker build
If your Dockerfile happens do be named differently (it really shouldn't), you can tell docker to use it by passing it to the -f or --file option:
docker build -f MyDockerfile

Resources