Skip to content

Docker:Run

Flags

-p, --publish=[]
호스트에 연결된 컨테이너의 특정 포트를 외부에 노출합니다. 보통 웹 서버의 포트를 노출할 때 주로 사용합니다.
{호스트 포트}:{컨테이너 포트}
-i, --interactive=false
표준 입력(stdin)을 활성화하며 컨테이너와 연결(attach)되어 있지 않더라도 표준 입력을 유지합니다.
-t, --tty=false
TTY 모드(pseudo-TTY)를 사용합니다. Bash를 사용하려면 이 옵션을 설정해야 합니다. 이 옵션을 설정하지 않으면 명령을 입력할 수는 있지만 셸이 표시되지 않습니다.
--restart=[POLICY]
종료시 컨테이너를 다시 시작해야하거나 시작하지 않아야하는 방법에 대한 다시 시작 정책을 지정할 수 있습니다.
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

아래와 같은 옵션을 사용하여 리소스를 제한할 수 있다.

  • CPU shares, via -c flag. (이 옵션은 상대적인 값으로 정의되며, 1024를 기본값으로 적용한다.)
  • Memory limit, via -m flag.
  • Specific CPU cores, via --cpuset flag.

마지막으로, docker stats명령으로 컨테이너 상태를 모니터링 할 수 있다.

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