도커는 기본적으로 유닉스 도메인 소켓을 이용해서 통신을 한다. 소켓의 주소는 unix:///var/run/docker.socket 으로 root만 사용할 수 있다.
# ls -al /var/run/docker.sock
srw-rw---- 1 root docker 0 Oct 10 10:04 /var/run/docker.sock
도커 API를 원격에서 사용하고 싶다면, 인터넷 주소에 바인드 하도록 설정을 변경하면 된다. CLI상에서는 -H tcp://0.0.0.0:4000을 주고 실행하면 되지만, 설정으로 관리하는게 편하다. /lib/systemd/system/docker.server를 수정했다.
# curl -X GET http://192.168.56.50:4000/containers/c86c05009275/export > mycontainer.tar
혹은
# curl -X GET http://192.168.56.50:4000/containers/c86c05009275/export -o mycontainer.tar
아래와 같이 export한 tar 파일로 부터 이미지를 만들 수 있다.
# cat container01.tar | docker import - ubuntu-2-export:latest
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu-2-export latest dc3aa0df9eab About a minute ago 259.8 MB
...
이미지 만들기
export한 tar 파일 혹은 다른 이미지로 부터 새로운 이미지를 만들 수 있다.
POST /images/create?fromImage=ubuntu HTTP/1.1
쿼리 파라미터
fromImage : pull 할 이미지의 이름
fromSrc : 파일로 부터 import 한다. URL을 이용해서 원격에 있는 파일을 import 할 수 있다.
repo : Repository 이름
tag : 태그
registry
앞서 export한 container01.tar 파일로 부터 새로운 이미지를 만들어보자.
# curl -XPOST http://localhost:4000/images/create?fromSrc=http://localhost/container01.tar\&repo=ubuntu-10-export\&tag=latest
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu-10-export latest 945d73fe9249 6 seconds ago 259.8 MB
# curl -v -X POST localhost:4000/containers/23e9251030c0/start
HTTP/1.1 204 No Content
* Server Docker/1.8.2 (linux) is not blacklisted
Server: Docker/1.8.2 (linux)
Date: Fri, 23 Oct 2015 14:52:38 GMT
컨테이너 stop
POST /containers/(id)/stop
컨테이너 아이디가 id인 컨테이너를 stop 시킨다.
# curl -v -X POST localhost:4000/containers/23e9251030c0/stop
HTTP/1.1 204 No Content
* Server Docker/1.8.2 (linux) is not blacklisted
Server: Docker/1.8.2 (linux)
Date: Fri, 23 Oct 2015 14:56:22 GMT
컨테이너 restart
POST /containers/e90e34656806/restart?t=5 HTTP/1.1
Contents
Docker Remote API
환경 설정
# curl -L http://192.168.56.50:4000/version | json_pp { "GitCommit" : "0a8c2e3", "KernelVersion" : "3.19.0-15-generic", "GoVersion" : "go1.4.2", "ApiVersion" : "1.20", "Arch" : "amd64", "Version" : "1.8.2", "Os" : "linux", "BuildTime" : "Thu Sep 10 19:21:21 UTC 2015" }컨테이너
컨테이너 목록
# curl -L http://192.168.56.50:4000/containers/json?all=1 [ { "Labels" : null, "HostConfig" : { "NetworkMode" : "default" }, "Image" : "ubuntu", "Status" : "Exited (0) 16 hours ago", "Ports" : [], "Command" : "/bin/bash", "Id" : "528f507ccfa6ac6fe5a4750917c534baa8e05529a23b647eae467f954f9f62aa", "Created" : 1444393004, "Names" : [ "/yundream74" ] }, { "Labels" : null, "HostConfig" : {}, "Image" : "ubuntu", "Status" : "Created", "Ports" : [], "Command" : "/bin/bash", "Id" : "c86c05009275c50a5ca74e86040359fd4851b592d02e254425fcb63714a80417", "Created" : 1444391366, "Names" : [ "/yundream84" ] }, { "Status" : "Created", "Labels" : {}, "HostConfig" : { "NetworkMode" : "default" }, "Image" : "ubuntu", "Id" : "a936892f043b16b3769270f87f449958640a76205bfd508b1323e6109443daae", "Names" : [ "/modest_lumiere" ], "Created" : 1443838880, "Ports" : [], "Command" : "--name container01 /bin/bash" } ]컨테이너 생성
# curl -X POST http://192.168.56.50:4000/containers/create # data.json { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": [ "date" ], "Entrypoint": "", "Image": "ubuntu", "Labels": { "com.example.vendor": "Acme", "com.example.license": "GPL", "com.example.version": "1.0" }, "Mounts": [ { "Source": "/data", "Destination": "/data", "Mode": "ro,Z", "RW": false } ], "WorkingDir": "", "NetworkDisabled": false, "MacAddress": "12:34:56:78:9a:bc", "ExposedPorts": { "22/tcp": {} }, "HostConfig": { "Binds": ["/tmp:/tmp"], "Links": ["redis3:redis"], "LxcConf": {"lxc.utsname":"docker"}, "Memory": 0, "MemorySwap": 0, "CpuShares": 512, "CpuPeriod": 100000, "CpusetCpus": "0,1", "CpusetMems": "0,1", "BlkioWeight": 300, "MemorySwappiness": 60, "OomKillDisable": false, "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, "PublishAllPorts": false, "Privileged": false, "ReadonlyRootfs": false, "Dns": ["8.8.8.8"], "DnsSearch": [""], "ExtraHosts": null, "VolumesFrom": ["parent", "other:ro"], "CapAdd": ["NET_ADMIN"], "CapDrop": ["MKNOD"], "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, "NetworkMode": "bridge", "Devices": [], "Ulimits": [{}], "LogConfig": { "Type": "json-file", "Config": {} }, "SecurityOpt": [""], "CgroupParent": "" } }HTTP/1.1 201 Created Content-Type: application/json { "Id":"e90e34656806" "Warnings":[] }- LxcConf
- PortBindings
- PublishAllPorts
- Privileged
- ReadonlyRootfs
- Dns
- DnsSearch
- ExtraHosts
- VolumesFrom
- CapAdd
- CapDrop
- RestartPolicy
- NetworkMode
- Devices
- Ulimits
- SecurityOpt
- LogConfig
- CgroupParent
응답 코드들Inspect 컨테이너
# curl -L http://192.168.56.50:4000/containers/528f507ccfa6/json { "ExecIDs" : null, "Mounts" : [ { "RW" : true, "Mode" : "", "Destination" : "/workspace", "Source" : "/volumes/yundream74/workspace" } ], "MountLabel" : "", "NetworkSettings" : { "PortMapping" : null, "LinkLocalIPv6Address" : "", "IPAddress" : "", "SandboxKey" : "", "GlobalIPv6Address" : "", "HairpinMode" : false, "GlobalIPv6PrefixLen" : 0, "Ports" : null, "EndpointID" : "", "IPPrefixLen" : 0, "IPv6Gateway" : "", "SecondaryIPv6Addresses" : null, "SecondaryIPAddresses" : null, "NetworkID" : "", "Gateway" : "", "Bridge" : "", "LinkLocalIPv6PrefixLen" : 0, "MacAddress" : "" }, "Path" : "/bin/bash", "ExecDriver" : "native-0.2", "RestartCount" : 0, "ProcessLabel" : "", "LogPath" : "/var/lib/docker/containers/528f507ccfa6ac6fe5a4750917c534baa8e05529a23b647eae467f954f9f62aa/528f507ccfa6ac6fe5a4750917c534baa8e05529a23b647eae467f954f9f62aa-json.log", "GraphDriver" : { "Data" : null, "Name" : "aufs" }, "Name" : "/yundream74", "HostnamePath" : "/var/lib/docker/containers/528f507ccfa6ac6fe5a4750917c534baa8e05529a23b647eae467f954f9f62aa/hostname", "ResolvConfPath" : "/var/lib/docker/containers/528f507ccfa6ac6fe5a4750917c534baa8e05529a23b647eae467f954f9f62aa/resolv.conf", "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", "Config" : { "OnBuild" : null, "Env" : null, "AttachStderr" : true, "VolumeDriver" : "", "Hostname" : "528f507ccfa6", "Labels" : null, "Domainname" : "", "StdinOnce" : false, "OpenStdin" : false, "PublishService" : "", "ExposedPorts" : null, "MacAddress" : "", "AttachStdout" : true, "NetworkDisabled" : false, "Volumes" : null, "AttachStdin" : false, "User" : "root", "Image" : "ubuntu", "Entrypoint" : null, "Tty" : true, "WorkingDir" : "", "Cmd" : [ "/bin/bash" ] }, "Driver" : "aufs", "AppArmorProfile" : "", "Args" : [], "Id" : "528f507ccfa6ac6fe5a4750917c534baa8e05529a23b647eae467f954f9f62aa", "HostConfig" : { "LxcConf" : null, "Dns" : null, "VolumesFrom" : null, "SecurityOpt" : null, "Memory" : 0, "LogConfig" : { "Config" : {}, "Type" : "json-file" }, "ExtraHosts" : null, "ContainerIDFile" : "", "Devices" : null, "CgroupParent" : "", "RestartPolicy" : { "Name" : "", "MaximumRetryCount" : 0 }, "BlkioWeight" : 0, "PidMode" : "", "Binds" : [ "/volumes/yundream74/workspace:/workspace" ], "DnsSearch" : null, "OomKillDisable" : false, "GroupAdd" : null, "CpuPeriod" : 0, "CpuQuota" : 0, "ReadonlyRootfs" : false, "PortBindings" : null, "CpusetCpus" : "", "MemorySwap" : 0, "Ulimits" : null, "CapAdd" : [ "NET_ADMIN" ], "UTSMode" : "", "IpcMode" : "", "PublishAllPorts" : false, "NetworkMode" : "default", "Privileged" : false, "CpusetMems" : "", "ConsoleSize" : [ 0, 0 ], "CapDrop" : [ "MKNOD" ], "Links" : null, "CpuShares" : 0, "MemorySwappiness" : null }, "Created" : "2015-10-09T12:16:44.609380457Z", "HostsPath" : "/var/lib/docker/containers/528f507ccfa6ac6fe5a4750917c534baa8e05529a23b647eae467f954f9f62aa/hosts", "State" : { "Dead" : false, "Restarting" : false, "FinishedAt" : "2015-10-09T12:18:17.019078028Z", "Error" : "", "ExitCode" : 0, "Paused" : false, "Pid" : 0, "Running" : false, "OOMKilled" : false, "StartedAt" : "2015-10-09T12:17:05.995285929Z" } }컨테이너에서 실행 중인 프로세스 목록
# curl -X GET http://192.168.56.50:4000/containers/c86c05009275/top { "Titles" : [ "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" ], "Processes" : [ [ "root", "9793", "952", "0", "20:14", "pts/1", "00:00:00", "/bin/bash" ], [ "root", "17954", "952", "0", "23:29", "pts/4", "00:00:00", "/bin/bash" ] ] }이미지
export
이미지 만들기
- fromImage : pull 할 이미지의 이름
- fromSrc : 파일로 부터 import 한다. URL을 이용해서 원격에 있는 파일을 import 할 수 있다.
- repo : Repository 이름
- tag : 태그
- registry
앞서 export한 container01.tar 파일로 부터 새로운 이미지를 만들어보자.이미지 목록
# curl -XGET http://localhost:4000/images/json [ { "Created" : 1445012842, "VirtualSize" : 259816161, "ParentId" : "", "Id" : "dc3aa0df9eab01b6684ada025d430198d65f3f8c14150b365794069452bbd22d", "RepoTags" : [ "ubuntu-2-export:latest" ], "Labels" : null, "Size" : 259816161, "RepoDigests" : [] }, { "Size" : 259816161, "Labels" : null, "RepoDigests" : [], "RepoTags" : [ "ubuntu-1-export:latest" ], "Id" : "d991a0fdaf6b93ce48e5046b5c17e2a05ff25b2b2eeaf4e4cb50e36b72dce162", "Created" : 1445012629, "VirtualSize" : 259816161, "ParentId" : "" ]이미지 상세 정보
# curl -X GET http://localhost:4000/images/ubuntu-10-export/json { "Config" : { "Env" : null, "Volumes" : null, "Tty" : false, "PublishService" : "", "StdinOnce" : false, "NetworkDisabled" : false, "MacAddress" : "", "AttachStdout" : false, "Domainname" : "", "Entrypoint" : null, "Image" : "", "WorkingDir" : "", "User" : "", "ExposedPorts" : null, "OpenStdin" : false, "Hostname" : "", "AttachStdin" : false, "AttachStderr" : false, "Cmd" : null, "VolumeDriver" : "", "OnBuild" : null, "Labels" : null }, "GraphDriver" : { "Data" : null, "Name" : "aufs" }, "DockerVersion" : "1.8.2", "Container" : "", "Os" : "linux", "ContainerConfig" : { "NetworkDisabled" : false, "PublishService" : "", "StdinOnce" : false, "Tty" : false, "Volumes" : null, "Env" : null, "MacAddress" : "", "Domainname" : "", "AttachStdout" : false, "User" : "", "WorkingDir" : "", "Image" : "", "Entrypoint" : null, "ExposedPorts" : null, "OpenStdin" : false, "AttachStdin" : false, "Hostname" : "", "OnBuild" : null, "VolumeDriver" : "", "Cmd" : null, "AttachStderr" : false, "Labels" : null }, "Author" : "", "Id" : "27f3e12f385ea9f4f4b5af5cefa2457274b8da77671ec97b32b9a2c42cd41f7d", "Created" : "2015-10-16T16:54:23.716059412Z", "VirtualSize" : 259816161, "Architecture" : "amd64", "Comment" : "Imported from http://localhost/container01.tar", "Parent" : "", "Size" : 259816161 }컨테이너 start
컨테이너 stop
컨테이너 restart
컨테이너 kill
Recent Posts
Archive Posts
Tags