What are other useful Docker flags?

083

Here are some other useful Docker flags that can be used with the docker run command:

  1. -d: Runs the container in detached mode (in the background).

    docker run -d <image_name>
  2. -p: Maps a port from the container to the host.

    docker run -p <host_port>:<container_port> <image_name>
  3. -e: Sets environment variables inside the container.

    docker run -e "ENV_VAR_NAME=value" <image_name>
  4. --name: Assigns a name to the container.

    docker run --name <container_name> <image_name>
  5. -v: Mounts a volume or directory from the host into the container.

    docker run -v <host_directory>:<container_directory> <image_name>
  6. --network: Connects the container to a specific network.

    docker run --network <network_name> <image_name>
  7. --restart: Specifies the restart policy for the container (e.g., always, unless-stopped).

    docker run --restart always <image_name>
  8. -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.

0 Comments

no data
Be the first to share your comment!