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

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.

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}" .

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.

Docker build dockerfile

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/

Docker image versioning and lifecycle management

I am getting into Docker and am trying to better understand how it works out there in the "real world".
It occurs to me that, in practice:
You need a way to version Docker images
You need a way to tell the Docker engine (running on a VM) to stop/start/restart a particular container
You need a way to tell the Docker engine which version of a image to run
Does Docker ship with built-in commands for handling each of these? If not what tools/strategies are used for accomplishing them? Also, when I build a Docker image (via, say, docker build -t myapp .), what file type is produced and where is it located on the machine?
docker has all you need to build images and run containers. You can create your own image by writing a Dockerfile or by pulling it from the docker hub.
In the Dockerfile you specify another image as the basis for your image, run command install things. Images can have tags, for example the ubuntu image can have the latest or 12.04 tag, that can be specified with ubuntu:latest notation.
Once you have built the image with docker build -t image-name . you can create containers from that image with `docker run --name container-name image-name.
docker ps to see running containers
docker rm <container name/id> to remove containers
Suppose we have a docker file like bellow:
->Build from git without versioning:
sudo docker build https://github.com/lordash/mswpw.git#fecomments:comments
in here:
fecomments is branch name and comments is the folder name.
->building from git with tag and version:
sudo docker build https://github.com/lordash/mswpw.git#fecomments:comments -t lordash/comments:v1.0
->Now if you want to build from a directory: first go to comments directory the run command sudo docker build .
->if you want to add tag you can use -t or -tag flag to do that:
sudo docker build -t lordash . or sudo docker build -t lordash/comments .
-> Now you can version your image with the help of tag:
sudo docker build -t lordash/comments:v1.0 .
->you can also apply multiple tag to an image:
sudo docker build -t lordash/comments:latest -t lordash/comments:v1.0 .

Resources