도커는 기본적으로 유닉스 도메인 소켓을 이용해서 통신을 한다. 소켓의 주소는 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
환경 설정
컨테이너
컨테이너 목록
컨테이너 생성
Inspect 컨테이너
컨테이너에서 실행 중인 프로세스 목록
이미지
export
이미지 만들기
이미지 목록
이미지 상세 정보
컨테이너 start
컨테이너 stop
컨테이너 restart
컨테이너 kill
Recent Posts
Archive Posts
Tags