Docker Build and Run In One Command

09-13-2019

Option 1)

1
docker build -t myapp . && docker run -it myapp

Option 2) Preferred

1
docker run -it $(docker build -q .)

By using the -q flag Docker will build the image according to our Dockerfile in quiet mode, and only return the hash of the generated Docker image. The hash value is then passed into the docker run... command.

I like to add the --rm flag so the container is removed when we exit the interactive session

Example:

1
docker run -it --rm $(docker build -q .)