Is it possible to pass arguments in dockerfile?

I am trying to pass arguments to dockerfile. My dockerfile:
FROM ubuntu:latest
MAINTAINER Abhay Kumar Somani
CMD echo $var1

Now I want to pass the value for var1 while starting the docker instead of making it static. For example
docker run -i -t ABHAYKUMARSOMANI should perform echo ABHAYKUMARSOMANI after starting the container.
Is there any way I can achieve this?

you can pass an environment variable with the -e switch, so your command to start will be

docker run -i -t -e var1=ABHAYKUMARSOMANI

Create a shell script like the following, in the same directory as your Dockerfile:

echo "$1"

Then change the Dockerfile to add that script and use it as the entrypoint script:

FROM ubuntu:16.04
CMD ["default_cmd"]  # delete this line

When you docker run this, Docker runs the ENTRYPOINT, passing either what you passed on the command line or the CMD as arguments to it.

$ docker build -t test .
$ docker run test
$ docker run test hi
$ docker run test hello world

Note that this setup can interfere with some more normal debugging setups

$ docker run test /bin/bash
$ docker run --entrypoint /bin/bash test