Sobes.tech
Junior — Middle

What parameters and options are available when launching a Docker container to configure its behavior?

sobes.tech AI

Answer from AI

When launching a Docker container using the docker run command, there are many parameters available to configure its behavior. Here are the main ones:

  • -d or --detach — run the container in the background.
  • -p or --publish — port forwarding from the host to the container, e.g., -p 8080:80.
  • -v or --volume — mounting volumes or directories, e.g., -v /host/path:/container/path.
  • --name — assign a name to the container.
  • --env or -e — pass environment variables, e.g., -e ENV=prod.
  • --rm — automatically remove the container after stopping.
  • --network — connect the container to a specific network.
  • --restart — container restart policy (e.g., always, on-failure).
  • --memory and --cpus — resource limits for memory and CPU.

Example of launching a container with port forwarding, environment variable, and name:

docker run -d -p 8080:80 -e ENV=production --name my_container nginx