Docker Build and Run In One Command
In this video we look at 2 ways to build and run a docker image as a container in one simple command. This is useful when testing a Dockerfile, application, logic, or really any reason you might use Docker.
Option 1)
docker build -t myapp . && docker run -it myapp
Option 2) Preferred
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:
docker run -it --rm $(docker build -q .)