docker build command with variable in gitlab CI - docker

I have following docker command in gitlab CI file .gitlab-ci.yml
docker build --pull -t "${CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG}" .
getting following error after build stage:
invalid argument "." for "-t, --tag" flag: invalid reference format
See 'docker build --help'.
any help , how to pass the variables ? Thanks

The way you've defined the tag is incorrect, and the result will be an empty string. That's why you get an error regarding the tag.
There is no need to add brackets, and you can use $ENV_VARIABLE. In this case, you can use the following command:
docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" .
If you want to use brackets:
docker build --pull -t "${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}" .

Related

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” requires exactly 1 argument

I know there are several posts like this but nothing has worked so far, I have a Dockerfile inside a folder and I have tried the following commands:
docker build <full/path> --label test1="test2" --tag myImage
docker build --file <full/path>/Dockerfile --label test1="test2" --tag myImage
docker build Dockerfile --label test1="test2" --tag myImage <full/path>
docker build --label test1="test2" --tag myImage --file <full/path>/Dockerfile
docker build Dockerfile --label test1="test2" --tag myImage .
But I always get this error docker build" requires exactly 1 argument.
Strangely enough this only happens with an specific Dockerfile, I have another one in a similar folder structure and that one works fine:
/folder1
/folder2
Dockerfile // This one works
more files...
/folder3
Dockerfile // This one fails
more files...
Notice that I'm not running the commands from that same folders so I have to use absolute paths (since I'm running the commands from Java API) but it is still strange that one Docker file works and the other one fails since the folder structure is the same.
So what I know is that optional arguments have to be BEFORE the only argument.
The only argument is your dockerfile / your path to the lockerfile.
docker build --label "test1=test2" --tag "myImage" .

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' is not a docker command

I was following https://cloud.google.com/container-registry/docs/quickstart documentation to build the Docker image;
Run the following Docker command from the directory containing the image's files:
docker build -t quickstart-image .
But then I get the error message:
docker: 'build' is not a docker command.
My docker version: version 18.09.0, build 4d60db4
Why is the command not working? Is it because of my docker version?
not sure if you still have this problem, but could you verify that there are no hidden characters in your
docker build -t quickstart-image .
I get this error when I copy-paste from either libre office or word
funny fix for funny problems

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/

Resources