[MacOS] file descriptor와 process limit 늘리기

맥에서 “too many open files” 에러 나면서 안되는 경우가 있다. Linux에 비해 limits이 너무 적기 때문이다.

Big sur 기준

  1. sudo vi /Library/LaunchDaemons/limit.maxfiles.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>524288</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>

2. sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist

3. sudo vi /Library/LaunchDaemons/limit.maxproc.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>Label</key>
        <string>limit.maxproc</string>
      <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxproc</string>
          <string>2048</string>
          <string>2048</string>
        </array>
      <key>RunAtLoad</key>
        <true />
      <key>ServiceIPC</key>
        <false />
    </dict>
  </plist>

4. sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist

5. sudo sysctl -w kern.maxfiles=5242880

6. sudo sysctl -w kern.maxfilesperproc=524288

7. Reboot

참고: https://wilsonmar.github.io/maximum-limits/

[Docker] docker commands

실행 중인 docker process (machine) 보기

docker ps

실행 중 + 실행 중이 아닌 docker process 보기

docker ps -a

docker 이미지 보기

docker images

docker process 삭제

docker rm -rf [container name]

docker 이미지 삭제

docker rmi [image name]

docker 이미지 가져오기

docker pull [image name]

docker process 시작

docker start [container name]

docker process 중지

docker stop [container name]

실행 중인 모든 컨테이너 강제 종료

docker kill $(docker ps -q -f status=running)

실행 중인 모든 컨테이너 중지

docker stop $(docker ps -q -f status=running)

종료된 모든 컨테이너 삭제

docker rm $(docker ps -q -f status=exited)

시스템 상의 모든 이미지 삭제

docker image rm -f $(docker image ls -q)

docker 로그 보기

docker logs [container name]

docker network 삭제

docker network prune -f

alias해서 간편히 사용하기

alias dockerkill='docker kill $(docker ps -q -f status=running)'
alias dockerstop='docker stop $(docker ps -q -f status=running)'
alias dockerrm='docker rm $(docker ps -q -f status=exited)'
alias dockerimgrm='docker image rm -f $(docker image ls -q)'
alias dockernetprune='docker network prune -f'

docker cli 실행

$ docker exec -it cli /bin/bash