☰ See All Chapters |
docker run
docker run command primary function is to build and run containers. The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command. By adding arguments to the run command, you can configure a container to run in detached mode, set a container name, mount a volume, and perform many more tasks. Below is the syntax of docker run command.
docker run syntax
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [arg0 arg1...] |
The docker run command must specify an IMAGE to derive the container from, rest all written inside [] are optional.
After docker image is created you will have to run image. You should define what should happen when you run your image. For example, when you run your image it should start application servers, it should start Database services. Sometimes you may need to set environment specific settings before starting any services... so on. To execute your desired tasks when docker image is run you have to set your executable instructions from either RUN command or from ENTRYPOINT command. When docker run command is executed it runs the RUN command or from ENTRYPOINT commands instructions. You can read more about ENTRYPOINT command from Docker ENTRYPOINT Command chapter and RUN command from Docker Run Command.
Now if you are confused between docker RUN command and docker run, this is the difference, docker run command is used to run image and docker RUN command is an instruction used inside Dockerfile to define how docker run command should run the image.
With the docker run [OPTIONS] an operator can add to or override the image defaults set by a developer in Dockerfile from ENTRYPOINT or RUN instructions. And, additionally, operators can override nearly all the defaults set by the Docker runtime itself. The operator’s ability to override image and Docker runtime defaults are why run has more options than any other docker command.
Docker attached vs detached mode
All Chapters