docker 공부

docker 2016. 7. 24. 05:50


* docker는 Go 로 만들어져 있다 .



* 컨테이너 명령어는 아래 github에 있다.


https://github.com/docker/docker/tree/master/api/client/container


run 커맨드는 create 커맨드와 run 커맨드를 하나로 합쳐 준 기능이다.





* 도커 이미지/컨테이너

도커 이미지는 파일, 

도커 컨테이너는 프로세스




* docker 프로세스 목록 보기

$ docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                    NAMES

66825389a870        hello-world         "/hello"                 40 hours ago        Exited (0) 40 hours ago                             hungry_chandrasekhar

9fb0fc1311ee        054c4599963c        "/bin/sh -c 'mkdir -p"   5 days ago          Exited (0) 5 days ago                               gigantic_jang

f7dd0d66158a        380da3b4d062        "/bin/sh -c 'yum grou"   5 days ago          Exited (0) 5 days ago                               infallible_bose

5ccaea4b7cb9        kite-dns            "sh /app/start"          22 months ago       Exited (0) 11 months ago   172.17.42.1:53->53/udp   kite-dns

e194ffa881eb        dockerfile/ghost    "/bin/bash"              23 months ago       Exited (0) 23 months ago                            prickly_archimedes

123a8a34e793        dockerfile/ghost    "bash /ghost-start"      23 months ago       Exited (0) 22 months ago   0.0.0.0:2368->2368/tcp   cranky_pasteur

e7dff68d8231        dockerfile/ghost    "bash /ghost-start"      23 months ago       Exited (0) 23 months ago                            hungry_sinoussi

41088b37ad02        dockerfile/ghost    "bash /ghost-start"      23 months ago       Exited (0) 23 months ago                            stoic_almeida

36f61ab4f3ae        dockerfile/ghost    "bash /ghost-start"      23 months ago       Exited (0) 23 months ago                            angry_curie


exited 와 up으로 대충 구분할 수 있다. exited는 종료된 것, up은 실행 중임을 의미한다.


docker ps 는 실행 중인 도커 프로세스의 목록을 출력한다.


$ docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES

76d768dbe13c        wordpress           "/entrypoint.sh apach"   About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp   wordpress

a54634841ccd        mysql:5.7           "docker-entrypoint.sh"   About an hour ago   Up About an hour    3306/tcp               wordpressdb




* 도커 컨테이너를 시작하려면 docker start를 실행한다.

$ docker start wordexpress


* 도커 컨테이너를 종료하려면 docker stop를 실행한다.

$ docker stop wordexpress



* 도커 컨테이너를 삭제하려면 docker rm을 실행한다.


$ docker ps -a  | grep hello

5f615fc3de99        hello-world         "bash"                   About an hour ago   Created                                                 furious_wozniak

686db8babcdb        hello-world         "/hello"                 About an hour ago   Exited (0) About an hour ago                            evil_bohr

66825389a870        hello-world         "/hello"                 2 days ago          Exited (0) 2 days ago                                   hungry_chandrasekhar

~$ docker rm 5f615fc3de99  686db8babcdb  66825389a870

5f615fc3de99

686db8babcdb

66825389a870

~$ docker ps -a  | grep hello

// 없음





* 도커 컨테이너에 접근하려면 docker exec container_id /bin/bash를 실행한다.




* 도커 컨네이버 검색하려면 docker search 커맨드를 사용한다.

$docker search express

$docker search node

$docker search centos



* 도커 허브 로그인

$ docker login

Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.

Username:



* docker 명령어 잘 보기

docker 커맨드에 --help 잘 살펴보기



$ docker  --help

Usage: docker [OPTIONS] COMMAND [arg...]

       docker [ --help | -v | --version ]


A self-sufficient runtime for containers.


Options:


  --config=~/.docker              Location of client config files

  -D, --debug                     Enable debug mode

  -H, --host=[]                   Daemon socket(s) to connect to

  -h, --help                      Print usage

  -l, --log-level=info            Set the logging level

  --tls                           Use TLS; implied by --tlsverify

  --tlscacert=~/.docker/ca.pem    Trust certs signed only by this CA

  --tlscert=~/.docker/cert.pem    Path to TLS certificate file

  --tlskey=~/.docker/key.pem      Path to TLS key file

  --tlsverify                     Use TLS and verify the remote

  -v, --version                   Print version information and quit


Commands:

    attach    Attach to a running container

    build     Build an image from a Dockerfile

    commit    Create a new image from a container's changes

    cp        Copy files/folders between a container and the local filesystem

    create    Create a new container

    deploy    Create and update a stack from a Distributed Application Bundle (DAB)

    diff      Inspect changes on a container's filesystem

    events    Get real time events from the server

    exec      Run a command in a running container

    export    Export a container's filesystem as a tar archive

    history   Show the history of an image

    images    List images

    import    Import the contents from a tarball to create a filesystem image

    info      Display system-wide information

    inspect   Return low-level information on a container, image or task

    kill      Kill one or more running container

    load      Load an image from a tar archive or STDIN

    login     Log in to a Docker registry.

    logout    Log out from a Docker registry.

    logs      Fetch the logs of a container

    network   Manage Docker networks

    node      Manage Docker Swarm nodes

    pause     Pause all processes within one or more containers

    plugin    Manage Docker plugins

    port      List port mappings or a specific mapping for the container

    ps        List containers

    pull      Pull an image or a repository from a registry

    push      Push an image or a repository to a registry

    rename    Rename a container

    restart   Restart a container

    rm        Remove one or more containers

    rmi       Remove one or more images

    run       Run a command in a new container

    save      Save one or more images to a tar archive (streamed to STDOUT by default)

    search    Search the Docker Hu



$ docker login --help


Usage: docker login [OPTIONS] [SERVER]


Log in to a Docker registry.

If no server is specified, the default is defined by the daemon.


Options:

      --help              Print usage

  -p, --password string   Password

  -u, --username string   Username




$ docker run --help


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


Run a command in a new container


Options:

      --add-host value              Add a custom host-to-IP mapping (host:ip) (default [])

  -a, --attach value                Attach to STDIN, STDOUT or STDERR (default [])

      --blkio-weight value          Block IO (relative weight), between 10 and 1000

      --blkio-weight-device value   Block IO weight (relative device weight) (default [])

      --cap-add value               Add Linux capabilities (default [])

      --cap-drop value              Drop Linux capabilities (default [])

      --cgroup-parent string        Optional parent cgroup for the container

      --cidfile string              Write the container ID to the file

      --cpu-percent int             CPU percent (Windows only)

      --cpu-period int              Limit CPU CFS (Completely Fair Scheduler) period

      --cpu-quota int               Limit CPU CFS (Completely Fair Scheduler) quota

  -c, --cpu-shares int              CPU shares (relative weight)

      --cpuset-cpus string          CPUs in which to allow execution (0-3, 0,1)

      --cpuset-mems string          MEMs in which to allow execution (0-3, 0,1)

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

      --detach-keys string          Override the key sequence for detaching a container

      --device value                Add a host device to the container (default [])

      --device-read-bps value       Limit read rate (bytes per second) from a device (default [])

      --device-read-iops value      Limit read rate (IO per second) from a device (default [])

      --device-write-bps value      Limit write rate (bytes per second) to a device (default [])

      --device-write-iops value     Limit write rate (IO per second) to a device (default [])

      --disable-content-trust       Skip image verification (default true)

      --dns value                   Set custom DNS servers (default [])

      --dns-opt value               Set DNS options (default [])

      --dns-search value            Set custom DNS search domains (default [])

      --entrypoint string           Overwrite the default ENTRYPOINT of the image

  -e, --env value                   Set environment variables (default [])

      --env-file value              Read in a file of environment variables (default [])

      --expose value                Expose a port or a range of ports (default [])

      --group-add value             Add additional groups to join (default [])

      --health-cmd string           Command to run to check health

      --health-interval duration    Time between running the check

      --health-retries int          Consecutive failures needed to report unhealthy

      --health-timeout duration     Maximum time to allow one check to run

      --help                        Print usage

  -h, --hostname string             Container host name

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

      --io-maxbandwidth string      Maximum IO bandwidth limit for the system drive (Windows only)

      --io-maxiops uint             Maximum IOps limit for the system drive (Windows only)

      --ip string                   Container IPv4 address (e.g. 172.30.100.104)

      --ip6 string                  Container IPv6 address (e.g. 2001:db8::33)

      --ipc string                  IPC namespace to use

      --isolation string            Container isolation technology

      --kernel-memory string        Kernel memory limit

  -l, --label value                 Set meta data on a container (default [])

      --label-file value            Read in a line delimited file of labels (default [])

      --link value                  Add link to another container (default [])

      --link-local-ip value         Container IPv4/IPv6 link-local addresses (default [])

      --log-driver string           Logging driver for container

      --log-opt value               Log driver options (default [])

      --mac-address string          Container MAC address (e.g. 92:d0:c6:0a:29:33)

  -m, --memory string               Memory limit

      --memory-reservation string   Memory soft limit

      --memory-swap string          Swap limit equal to memory plus swap: '-1' to enable unlimited swap

      --memory-swappiness int       Tune container memory swappiness (0 to 100) (default -1)

      --name string                 Assign a name to the container

      --network string              Connect a container to a network (default "default")

      --network-alias value         Add network-scoped alias for the container (default [])

      --no-healthcheck              Disable any container-specified HEALTHCHECK

      --oom-kill-disable            Disable OOM Killer

      --oom-score-adj int           Tune host's OOM preferences (-1000 to 1000)

      --pid string                  PID namespace to use

      --pids-limit int              Tune container pids limit (set -1 for unlimited)

      --privileged                  Give extended privileges to this container

  -p, --publish value               Publish a container's port(s) to the host (default [])

  -P, --publish-all                 Publish all exposed ports to random ports

      --read-only                   Mount the container's root filesystem as read only

      --restart string              Restart policy to apply when a container exits (default "no")

      --rm                          Automatically remove the container when it exits

      --runtime string              Runtime to use for this container

      --security-opt value          Security Options (default [])

      --shm-size string             Size of /dev/shm, default value is 64MB

      --sig-proxy                   Proxy received signals to the process (default true)

      --stop-signal string          Signal to stop a container, SIGTERM by default (default "SIGTERM")

      --storage-opt value           Set storage driver options per container (default [])

      --sysctl value                Sysctl options (default map[])

      --tmpfs value                 Mount a tmpfs directory (default [])

  -t, --tty                         Allocate a pseudo-TTY

      --ulimit value                Ulimit options (default [])

  -u, --user string                 Username or UID (format: <name|uid>[:<group|gid>])

      --userns string               User namespace to use

      --uts string                  UTS namespace to use

  -v, --volume value                Bind mount a volume (default [])

      --volume-driver string        Optional volume driver for the container

      --volumes-from value          Mount volumes from the specified container(s) (default [])

  -w, --workdir string              Working directory inside the container




* 이미지를 도커 허브에 올릴 수 있다.

참고,  $ man Dockerfile


Posted by '김용환'
,