Docker build dockerfile - docker

I am trying to build a docker image from dockerfile which I have written.
docker build -f ~/www/node-beta.dockerfile
This however results in the error:
docker: "build" requires 1 argument. See 'docker build --help'.

The docker build command always requires a location argument. In this case you should use ~/www/ as the for the location argument, and the file name, "node-beta.dockerfile" for the -f (filename) argument.
docker build -f node-beta.dockerfile ~/www

sudo docker build -t yee/haw -f ~/www/node-beta.dockerfile ~/www/

Related

Dockerfile exists but Docker says it can't locate

I don't see why docker doesn't build my Dockerfile. The Dockerfile is present but is complaining it can't locate it. What am I missing here? I'm at my wits end right now.
Dockerfile is present, unless my eyes are playing tricks on me. I think it's spelled correctly too.
$ ls
Dockerfile pct runme.sh
$
Error message I'm getting when running docker build
$ cat /tmp/context.tar | docker build -f Dockerfile -t iii -
Sending build context to Docker daemon 665.6kB
Error response from daemon: Cannot locate specified Dockerfile: Dockerfile
$
So after playing with the docker build command, I got it working. I don't know how/why the person catted the tar file and then piped it to docker build but it worked for them but not for me.
The command that worked for me was:
$ docker build -f Dockerfile my_dir/ -t image_name

How to specify GIT_ACCESS_TOKEN for the docker build command?

I run this command
docker build GIT_ACCESS_TOKEN=my_token -t "${IMAGE}" .
and got this error
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
But as you see above, I do have a dot at the end of the docker build command. Besides, docker build . -t "${IMAGE}" works for me, so it seems the error is introduced at GIT_ACCESS_TOKEN part?
Are you looking for build-arg?
docker build --build-arg GIT_ACCESS_TOKEN=my_token -t "${IMAGE}" .

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.

Docker build,where to run?

I am learning Docker
docker build -t mm/cowsay .
Should I go to cowsay folder or should I run it from my home mm directory?
I have registered on Docker hub.
The docker build command follows instructions specified in a given Dockerfile, and outputs an image.
Syntax:
docker build \
-t <tag-of-output-image> \
-f <path-to-dockerfile>
If you use . instead of -f <path-to-dockerfile>, you are telling the Docker Engine to use the Dockerfile in the current directory.
So you need to run your command from where the Dockerfile exists.

How to pass command line arguments to a docker image

I run tests inside docker image and I need to pass custom arguments
all the time.
When I put arguments after image name docker thinks that argument is image name.
docker run -t -i image-name -s test.py
docker run -t -i image-name -- -s test.py
Error:
Failed no image test_arena2.py
Docker version 1.11.2, build b9f10c9
You can build your Dockerfile with a combination of ENTRYPOINT and CMD instructions, which will let you run containers with or without arguments, e.g:
FROM ubuntu
ENTRYPOINT ["/bin/echo"]
CMD ["hello"]
That says the entrypoint is the echo command, and the default argument is hello. Run a container with no arguments:
> docker run temp
hello
Run with arguments and they all get passed to the entrypoint command:
> docker run temp -s stackoverflow
-s stackoverflow
docker run -i is good to be the begin of your command line then set of arguments for the run command only then at the very last -t image with image name provided
Image name should always be at the end of docker run command i.e. as last parameter to the command. Are you fine with passing the values as environment variable using below command
docker run -e "ENV_VAR_NAME=VALUE" -it image_name

Resources