본문 바로가기

Devops/Docker

[Docker] Docker 명령어 정리 #2

도커 Log 확인

Usage:  docker logs [OPTIONS] CONTAINER


Fetch the logs of a container

Options:
      --details        Show extra details provided to logs
  -f, --follow         Follow log output
      --since string   Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
  -n, --tail string    Number of lines to show from the end of the logs (default "all")
  -t, --timestamps     Show timestamps
      --until string   Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)

 

docker logs -f local_db

 

도커 이미지로부터 새로운 Container 띄우기

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

 

-d, --detach                         Run container in background and print container ID

-i, --interactive                    Keep STDIN open even if not attached

-t, --tty                            Allocate a pseudo-TTY

--name string                    Assign a name to the container

-p <host port number>:<container port number>/<protocol>

 

docker run -dit --name local_db -p 1521:1521/tcp store/oracle/database-enterprise:12.2.0.1-slim

 

도커 Container 내부에서 명령어 실행

Usage:

 docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

The docker exec command runs a new command in a running container.

The command started using docker exec only runs while the container’s primary process (PID 1) is running, and it is not restarted if the container is restarted.

COMMAND will run in the default directory of the container. If the underlying image has a custom directory specified with the WORKDIR directive in its Dockerfile, this will be used instead.

 

COMMAND should be an executable, a chained or a quoted command will not work.

Example: docker exec -ti my_container "echo a && echo b" will not work, but docker exec -ti my_container sh -c "echo a && echo b" will.

Options🔗

Name, shorthand Default Description
--detach , -d   Detached mode: run command in the background
--detach-keys   Override the key sequence for detaching a container
--env , -e   API 1.25+
Set environment variables
--env-file   API 1.25+
Read in a file of environment variables
--interactive , -i   Keep STDIN open even if not attached
--privileged   Give extended privileges to the command
--tty , -t   Allocate a pseudo-TTY
--user , -u   Username or UID (format: <name|uid>[:<group|gid>])
--workdir , -w   API 1.35+
Working directory inside the container

docker exec -it local_db bash -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1@ORCLCDB as sysdba"

 

도커 Container <-> 로컬 파일 시스템 간 파일 전송

Usage:  docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
        docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

 

docker cp .\sdp_data.log 5bf21657842e:/home/oracle/temp

(로컬 파일 sdp_data.log를 Container 5bf21657842e 안에 /home/oracle/temp에 복사함)