Here are some other useful Docker flags that can be used with the docker run command:
-
-d: Runs the container in detached mode (in the background).
docker run -d <image_name> -
-p: Maps a port from the container to the host.
docker run -p <host_port>:<container_port> <image_name> -
-e: Sets environment variables inside the container.
docker run -e "ENV_VAR_NAME=value" <image_name> -
--name: Assigns a name to the container.
docker run --name <container_name> <image_name> -
-v: Mounts a volume or directory from the host into the container.
docker run -v <host_directory>:<container_directory> <image_name> -
--network: Connects the container to a specific network.
docker run --network <network_name> <image_name> -
--restart: Specifies the restart policy for the container (e.g., always, unless-stopped).
docker run --restart always <image_name> -
-it: Combines
-i(interactive) and-t(pseudo-TTY) to run an interactive terminal session.docker run -it <image_name>
These flags can be combined to customize the behavior of the container when it is run.
