[Docker] 기본 명령어

Tip 2017. 11. 2. 17:03

Docker

  • 리눅스 컨테이너 기술(기존 cgroup, LXC)
  • Image 기반으로 여러 Container구동 가능


Docker 기본 명령어

  • Container
    • 생성 및 실행
      • $ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
      • $ docker run --restart=always -d --privileged -P --name worker01 -p 49160:22 worker:0.1
    • 목록
      • $ docker ps [ -a ]
    • 중지
      • $ docker stop { container_id }
    • 삭제
      • $ docker rm { container_id }
    • 중지된 컨테이너 전부 삭제
      • $ docker rm -v $(docker ps -a -q -f status=exited)
    • 로그
      • $ docker logs { container_id }
      • $ docker logs --tail 10 { container_id }
    • 실시간 로그
      • $ docker logs -f { container_id }
    • 명령어 실행
      • $ docker exec -it { container_name } { /bin/bash }
  • Image
    • 생성
      • $ docker build -t { gen_image_name }
    • 목록
      • $ docker images [ -a ]
    • 다운로드
      • $ docker pull ubuntu:16.04
    • 삭제
      • $ docker rmi  { image_id }

Docker-compose 기본 명령어

  • 생성 및 실행
    • $ docker-compose up
  • 목록
    • $ docker-compose ps
  • 실행
    • $ docker-compose start
  • 중지
    • $ docker-compose stop
  • 삭제
    • $ docker-compose down
  • 명령어 실행
    • $ docker-compose exec
  • 로그
    • $ docker-compose logs -f


Reference


Posted by leechwin
,

구글번역기가 2019년 12월 4일로 서비스를 종료한다고 합니다. ㅠㅠ


비슷한 서비스로 아래의 링크를 참조해야할듯 합니다.


미드, 일드, 영드 등을 볼때 한글 자막을 구할 수 없는 난감한 경우, 구글 번역기를 통한 자막 생성방법(물론 한글 번역이 완벽하지는 않다 ㅠㅠ)


  1. 먼저 번역할 대상의 자막 파일을 구한다. (언어 불문, SMI, SRT, SUB 확장자를 가지는 자막파일)
  2. 구글 번역 툴킷에 접속
  3. 좌측 상단에 업로드 버튼을 클릭
  4. 번역할 컨텐츠 추가 > 파일 업로드 선택
  5. 자막 파일 선택 > 자막파일의 원래 언어 선택(영어등) > 번역할 언어 선택(한국어)
  6. 번역 업체 선택 화면이 나오면 좌측 하단에 아니오 클릭
  7. 진행중 표시가 나오면 해당 컬럼을 클릭 > 저장 클릭 > 완료 클릭 > 팝업에서 확인 클릭
  8. 해당 자막을 체크하고 다운로드 버튼을 누르면 다운로드된다.
    1. 주의: 변환된 자막이 하나만 있는경우 가끔 다운로드가 안되는 경우가 있다. 이때는 추가로 다른 자막파일을 위와 같은 과정으로 추가하고 2개이상의 자막을 체크하고 다운로드 받으면 된다.
  9. 변환된 자막으로 즐감하면 완료.


Posted by leechwin
,

Ubuntu 에서 sudo 권한이 필요할때 특정 사용자와 특정 명령어에 대해 root password를 물어보지 않고 실행되게 할 수 있다.


다음 명령어를 수행하면 sudo 권한 파일을 수정 할 수 있다.

  • $ sudo visudo
  • $ sudo visudo

    # # This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL:ALL) ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d # Allow member and tool # leechwin ALL=(ALL) NOPASSWD:ALL # leechwin ALL=(ALL) NOPASSWD: /usr/sbin/chroot, /bin/kill, /usr/bin/killall

  • visudo 수행 후 나오는 에디터 하단에 다음과 같은 형식으로 기술하면 된다.
    • {user} ALL=(ALL) NOPASSWD: {tool path}
  • leechwin 이라는 사용자에게 chroot, kill, killall 에대한 명령에 대해서 sudo 권한을 주어지게 할 경우 다음과 같이 기술 할수 있다.
    • leechwin ALL=(ALL) NOPASSWD: /usr/sbin/chroot, /bin/kill, /usr/bin/killall
  • command path 는 다음 명령으로 확인 가능하다.
    • $ which {tool name}

visudo 에서 수정된 파일은 다음 파일에 저장된다.

  • /etc/sudoers


'OS > Linux' 카테고리의 다른 글

[Ubuntu] tail 명령으로 로그 확인하기  (0) 2019.02.27
[Ubuntu] ln 명령으로 링크 만들기  (0) 2019.02.27
[Ubuntu] hostname 변경  (0) 2017.01.19
[Ubuntu] Word Count  (0) 2017.01.19
[Ubuntu] Memory 확인  (0) 2017.01.19
Posted by leechwin
,

winston에서는 로그 파일 관리를 위해 다음과 같은 설정을 제공한다.

  • File Transport Options
    • maxsize: Max size in bytes of the logfile, if the size is exceeded then a new file is created, a counter will become a suffix of the log file.
      • 로그파일의 최대 크기를 지정가능하고, 해당 크기를 넘을 경우 새로운 로그파일을 생성
        • ex) error.log, error1.log, error2.log
    • maxFiles: Limit the number of files created when the size of the logfile is exceeded.
      • 생성되는 로그 파일의 갯수를 지정가능하고, maxFiles 갯수를 넘어갈경우 가장 오래된 파일을 삭제하고 새로 생성
    • zippedArchive: If true, all log files but the current one will be zipped.
      • 로그파일을 zip 파일로 유지
  • 예제
    • 로그파일을 최대 100MB x 5 개로 유지
    • var fileAppender = new winston.transports.File({
          timestamp: _timestamp,
          formatter: _customFormatter,
          json: false,
          filename: 'filelog.log',
          maxsize: 104857600, // 100 MB = 1024 * 1024 * 100 = 104857600 Bytes
          maxFiles: 5
      });
      
  • winston-daily-rotate-file
    • Daily로 로그를 생성하고 싶을 경우 winston-daily-rotate-file 모듈을 사용하면 된다.


Posted by leechwin
,

Winston의 Log Format을 Customizing 하는 방법에 대해 알아본다.


Winston Log Format을 수정하기 위해서는 Winston Transport의 formatter 설정을 구현해야 한다.

  • timestamp 및 output format 함수를 재구현
function _timestamp() {
        return moment().format("YYYY-MM-DD HH:mm:ss.SSS");
}
function _customFormatter(options) {
    return options.timestamp() +
            ' ['+ options.level.toUpperCase() + ']' +
            '['+ options.meta.loggerName + '] ' +
            (!options.meta.clientMessage ? options.message : options.meta.clientMessage);
}
var consoleAppender = new winston.transports.Console({
    timestamp: _timestamp,
    formatter: _customFormatter
});
var fileAppender = new winston.transports.File({
    timestamp: _timestamp,
    formatter: _customFormatter,
    json: false,
    filename: 'filelog.log'
});


Posted by leechwin
,

[Ubuntu] hostname 변경

OS/Linux 2017. 1. 19. 16:00

Ubuntu에서 현재 컴퓨터의 이름인 hostname 을 변경하는 법에 대해 알아보자.


현재 hostname은 shell 에서 $ hostname 명령을 통하여 알 수 있다.


hostname을 수정하려면 다음 2개의 파일을 원하는 이름으로 수정하고 재부팅하면 hostname이 수정되어 반영된다. 

  • sudo vi /etc/hostname
  • sudo vi /etc/hosts

$ hostname

leechwin-linux $ cat /etc/hostname leechwin-linux $ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 leechwin-linux # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters



'OS > Linux' 카테고리의 다른 글

[Ubuntu] ln 명령으로 링크 만들기  (0) 2019.02.27
[Ubuntu] sudo 권한 등록  (0) 2017.08.09
[Ubuntu] Word Count  (0) 2017.01.19
[Ubuntu] Memory 확인  (0) 2017.01.19
[Ubuntu] Filesystem 용량 확인  (0) 2017.01.19
Posted by leechwin
,

[Ubuntu] Word Count

OS/Linux 2017. 1. 19. 15:47

Ubuntu 환경의 쉘에서 특정 word를 count하거나 특정 파일의 라인수를 카운트하는 wc 명령에 대해 알아보자.


$ wc --help

Usage: wc [OPTION]... [FILE]... or: wc [OPTION]... --files0-from=F Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. A word is a non-zero-length sequence of characters delimited by white space. With no FILE, or when FILE is -, read standard input. The options below may be used to select which counts are printed, always in the following order: newline, word, character, byte, maximum line length. -c, --bytes print the byte counts -m, --chars print the character counts -l, --lines print the newline counts --files0-from=F read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input -L, --max-line-length print the maximum display width -w, --words print the word counts --help display this help and exit --version output version information and exit GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/wc> or available locally via: info '(coreutils) wc invocation'

wc 명령은 다음과 같이 여러가지로 이용가능하다.
  • 특정 파일의 라인수 카운트

$ wc -l test.md

42 test.md
  • 특정 문자 카운트

    $ cat test.md | grep config | wc -l

    4 $ cat /proc/cpuinfo | grep processor | wc -l 8


    'OS > Linux' 카테고리의 다른 글

    [Ubuntu] sudo 권한 등록  (0) 2017.08.09
    [Ubuntu] hostname 변경  (0) 2017.01.19
    [Ubuntu] Memory 확인  (0) 2017.01.19
    [Ubuntu] Filesystem 용량 확인  (0) 2017.01.19
    [Ubuntu] 커널버전 및 Ubuntu 버전 확인  (0) 2017.01.18
    Posted by leechwin
    ,

    [Ubuntu] Memory 확인

    OS/Linux 2017. 1. 19. 11:59

    Ubuntu 환경에서 현재 메모리 사용량을 free 명령을 통해 알 수 있다.

    $ free -h

    total used free shared buff/cache available Mem: 7.8G 2.3G 3.6G 161M 1.9G 5.0G Swap: 46G 472K 46G



    $ free --help

    Usage: free [options] Options: -b, --bytes show output in bytes -k, --kilo show output in kilobytes -m, --mega show output in megabytes -g, --giga show output in gigabytes --tera show output in terabytes -h, --human show human-readable output --si use powers of 1000 not 1024 -l, --lohi show detailed low and high memory statistics -t, --total show total for RAM + swap -s N, --seconds N repeat printing every N seconds -c N, --count N repeat printing N times, then exit -w, --wide wide output --help display this help and exit -V, --version output version information and exit



    'OS > Linux' 카테고리의 다른 글

    [Ubuntu] hostname 변경  (0) 2017.01.19
    [Ubuntu] Word Count  (0) 2017.01.19
    [Ubuntu] Filesystem 용량 확인  (0) 2017.01.19
    [Ubuntu] 커널버전 및 Ubuntu 버전 확인  (0) 2017.01.18
    [Ubuntu] deb 파일 설치가 잘 안되는 경우  (0) 2017.01.05
    Posted by leechwin
    ,

    Ubuntu 환경에서 현재 Filesystem 사용량을 df 명령을 통해 알 수 있다.

    아래의 예제로는 현재 159G의 용량을 사용가능하다.

    $ df -h

    Filesystem Size Used Avail Use% Mounted on udev 3.9G 0 3.9G 0% /dev tmpfs 794M 9.7M 785M 2% /run /dev/sda2 184G 16G 159G 10% / tmpfs 3.9G 86M 3.8G 3% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup tmpfs 794M 48K 794M 1% /run/user/1000

    $ df --help

    Usage: df [OPTION]... [FILE]... Show information about the file system on which each FILE resides, or all file systems by default. Mandatory arguments to long options are mandatory for short options too. -a, --all include pseudo, duplicate, inaccessible file systems -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in units of 1,048,576 bytes; see SIZE format below -h, --human-readable print sizes in powers of 1024 (e.g., 1023M) -H, --si print sizes in powers of 1000 (e.g., 1.1G) -i, --inodes list inode information instead of block usage -k like --block-size=1K -l, --local limit listing to local file systems --no-sync do not invoke sync before getting usage info (default) --output[=FIELD_LIST] use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted. -P, --portability use the POSIX output format --sync invoke sync before getting usage info --total elide all entries insignificant to available space, and produce a grand total -t, --type=TYPE limit listing to file systems of type TYPE -T, --print-type print file system type -x, --exclude-type=TYPE limit listing to file systems not of type TYPE -v (ignored) --help display this help and exit --version output version information and exit Display values are in units of the first available SIZE from --block-size, and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set). The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). FIELD_LIST is a comma-separated list of columns to be included. Valid field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent', 'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page). GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Full documentation at: <http://www.gnu.org/software/coreutils/df> or available locally via: info '(coreutils) df invocation'


    'OS > Linux' 카테고리의 다른 글

    [Ubuntu] Word Count  (0) 2017.01.19
    [Ubuntu] Memory 확인  (0) 2017.01.19
    [Ubuntu] 커널버전 및 Ubuntu 버전 확인  (0) 2017.01.18
    [Ubuntu] deb 파일 설치가 잘 안되는 경우  (0) 2017.01.05
    [Jenkins] Jenkins 업데이트  (0) 2016.01.19
    Posted by leechwin
    ,

    Ubuntu 환경에서 커널버전 및 Ubuntu 버전을 확인하는 법에 대해 알아보자.


    커널버전 알아보기

      $ uname -a Linux leechwin-linux 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux $ cat /proc/version Linux version 4.4.0-59-generic (buildd@lgw01-11) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017

    Ubuntu 버전확인하기

      $ cat /etc/issue Ubuntu 16.04.1 LTS \n \l $ cat /etc/*release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS" NAME="Ubuntu" VERSION="16.04.1 LTS (Xenial Xerus)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 16.04.1 LTS" VERSION_ID="16.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" VERSION_CODENAME=xenial UBUNTU_CODENAME=xenial $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS Release: 16.04 Codename: xenial

    참고로 /etc/issue 파일은 내부에서 콘솔 로그인시 출력해주는 메시지이다.

    Posted by leechwin
    ,