Building image from a file

I am trying to build an image from a file other than Dockerfile 

[test@eilagcy1 Builds]$ docker build -f /home/test/Builds/filedoc -t mycont:v3

"docker build" requires exactly 1 argument(s).

See 'docker build --help'.

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

Build an image from a Dockerfile

[test@eilagcy1 Builds]$ ls -ltr filed*

-rw-rw-r--. 1 test test 85 Dec 7 13:15 filedoc

[test@eilagcy1 Builds]$ cat filedoc

FROM alpine:latest

RUN apk add --update htop && rm -rf /var/cache/apk/*

CMD ["htop"]

[test@eilagcy1 Builds]$ pwd


[test@eilagcy1 Builds]$

What is wrong with the above command?


  • post-author-pic
    Chad C

    Hello Anuraag, are you trying to create an image from scratch?

    You can use Docker’s reserved, minimal image, scratch, as a starting point for building containers. Using the scratch “image” signals to the build process that you want the next command in the Dockerfile to be the first filesystem layer in your image.

    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
    ADD hello /
    CMD ["/hello"]

    You can build this Docker image using this docker build command:

    docker build --tag hello .

    Don’t forget the "." character at the end, which sets the build context to the current directory.

    docker run --rm hello

    Please let us know how it goes! 

  • post-author-pic
    John M

    You also might want to start with a base image from DockerHub. Youcan use docker compose, and you can use a Dockerfile. Good luck - John

Looking For Team Training?

Learn More