Bash: docker: command not found

hi.
I’m doing Docker training and trying to build a new image: created “Docker” folder and then “Dockerfile” in VS code web.
In “Dockerfile”:
FROM nginx:latest

CMD echo “Hello World!”

And then, in VS code terminal :
coder@7bdf6dd50d4b:~/Extension$ docker build . -t myfirstimage:1
bash: docker: command not found

In CMD:
#ERROR: “docker buildx build” requires exactly 1 argument.
See ‘docker buildx build --help’.

Usage: docker buildx build [OPTIONS] PATH | URL | -

Start a build

Any workaround?
Thanks

2 Likes

You can build an image on the host or develop inside the contaier. The docker command doesn’t exist in the dev container and you used a different command on the host. It shows exactly what you need to do. The path parameter is missing the same way as you would need to use it when you run docker build and as you did it in the container.

If I misinterpreted something, please show exactly what you did. It is not entirely clear since I don’t see any command in the “In CMD” section. I just guess that it ran in Windows command line without an argument.

In CMD:

docker build . -t myfirstimage:1

[+] Building 0.1s (2/2) FINISHED docker:default
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 2B 0.0s
ERROR: failed to solve: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount358861243/Dockerfile: no such file or directory

Basically, i’m trying it in both VS and CMD and it fails, although it works on the Udemy course.
As i’m new to Docker, could you please provide detailed steps for resolution?
thx

You need to run the docker command in the same directory in which the file called “Dockerfile” can be found (or set the context and Dockerfile path manually). The error message the Dockerfile was not found in the context. If you think it is where it has to be, please share your folder structure so we can check it and notice if something is still wrong.


hey,
Although I’m opening the VS terminal from the Dockerfile, i’m getting the same error (attached).

What’s wrong here?
thx
P.S. I have deleted the old docker folder and Dockerfile, which were incorrectly set up, and recreated them, but getting the same error message as per below

And you are still running bash in a container which is I assume a dev container. If you want to run the docker command open cmd or powershell from Windows or open the project from the host without the dev environment feature.

I’m running “docker build” command in cmd from the “.docker” folder as attached, but getting the error message:
ERROR: failed to solve: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount237861459/Dockerfile: no such file or directory

On a separate note, when i’m trying to access: C:\Users\Public\Documents\Hyper-V\Virtual hard disk - there is nothing under “Documents”.

Example of my docker command:
C:\Users\My_Username\.docker\docker build . -t myfirstimage:1

Where exactly are the “Dockerfile” images saved on the disk?

The “Dockerfile” is not an image, but the file itself is anywhere you put it. If you saved it only in the dev container, then it is only in the container and you have to create it where you can access it from the host.

You could also make the docker socket available for a container, but I don’t recommend you to try it until you understand the basics. Make it work on the host, and then you can try more complicated configurations.

I wouldn’t try to run docker build in your user’s home. And definitely don’t try it in the .docker folder in your user’s home. That is for docker client configurations not for your source code.

I would recommend you to read my tutorial:

although it was tested only on Linux and macOS, so some parts of the tutorial will not work on Windows. At least not yet. The Getting started and the Docker chapter in the INTRO section should wourk. And some of the example projects too, but not the shell scripts.

i get the error of command not found: docker in my mac after installing the Docker desktop i follow these steps Install Docker Desktop on Mac | Docker Docs

After running this command

**sudo ln -s /Applications/Docker.app/Contents/Resources/bin/docker /usr/local/bin/docker**

error was resolved

1 Like

thank you @sankhla2 that solved it for me as well.

1 Like

If. you have a macbook, install docker using homebrew and it should work. If you have installed it using pip feel free to uninstall it