Skip to content
Search

Docker:Run

lastmod 2020-09-10created 2015-12-1416 edits

Flags

-p, --publish=[]
Exposes a specific port of the container, connected to the host, to the outside. Mostly used to expose a web server's port.
{호스트 포트}:{컨테이너 포트}
-i, --interactive=false
Enables standard input (stdin) and keeps standard input open even if not attached to the container.
-t, --tty=false
Uses TTY mode (pseudo-TTY). This option must be set to use Bash. Without this option you can type commands, but the shell is not displayed.
--restart=[POLICY]
Lets you specify a restart policy for how the container should or should not be restarted on exit.
Docker Documentation # Restart policies (--restart)
{|class="wikitable"

! Policy || Result |- | no | Do not automatically restart the container when it exits. This is the default. |- | on-failure[:max-retries] | Restart only if the container exits with a non-zero exit status. Optionally, limit the number of restart retries the Docker daemon attempts. |- | always | Always restart the container regardless of the exit status. When you specify always, the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container. |- | unless-stopped | Always restart the container regardless of the exit status, including on daemon startup, except if the container was put into a stopped state before the Docker daemon was stopped. |}

Limiting resource

Resources can be limited with the following options.

  • CPU shares, via -c flag. (This option is defined as a relative value, with 1024 applied as the default.)
  • Memory limit, via -m flag.
  • Specific CPU cores, via --cpuset flag.

Finally, container status can be monitored with the docker stats command.

CPU share constraint

By default, all containers get the same proportion of CPU cycles. This proportion can be modified by changing the container’s CPU share weighting relative to the weighting of all other running containers.

To modify the proportion from the default of 1024, use the -c or --cpu-shares flag to set the weighting to 2 or higher. If 0 is set, the system will ignore the value and use the default of 1024.

The proportion will only apply when CPU-intensive processes are running. When tasks in one container are idle, other containers can use the left-over CPU time. The actual amount of CPU time will vary depending on the number of containers running on the system.

For example, consider three containers, one has a cpu-share of 1024 and two others have a cpu-share setting of 512. When processes in all three containers attempt to use 100% of CPU, the first container would receive 50% of the total CPU time. If you add a fourth container with a cpu-share of 1024, the first container only gets 33% of the CPU. The remaining containers receive 16.5%, 16.5% and 33% of the CPU.

On a multi-core system, the shares of CPU time are distributed over all CPU cores. Even if a container is limited to less than 100% of CPU time, it can use 100% of each individual CPU core.

CPU Clock

Example

$ docker run --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1" \
    --lxc-conf="lxc.cgroup.cpu.shares = 1234"

See also

Favorite site

References


  1. How_to_monitor_Docker_resource_metrics_-_Datadog.pdf ↩

  2. Joinc_-_Cpu_and_memory_limit_of_the_container.pdf ↩

author Zer0 sitemap