2017년 7월 7일 금요일

Docker and Swarm





Make Private Registry (Deploy a registry server)

Run a local registry

Use a command like the following to start the registry container

  $ docker run -d -p 5000:5000 --restart=always --name registry registry:2
or you can change service port number (5555)
  $ docker run -d -p 5555:5000 --restart=always --name registry registry:2  

The registry is now ready to use.

Copy an image from Docker Hub to your registry

Pull the busybox:ubuntu-14.04  or busybox:1.26

  $ docker  pull  busybox:1.26

Tag the image as localhost:5000/andrew-busybox
  
  $ docker  tag  busybox:1.26  localhost:5000/andrew-busybox

Push the image to the local registry running at localhost:5000

  $ docker  push  localhost:5000/andrew-busybox

Verify if the image is on private registry server

  $ curl  -X GET  http://localhost:5000/v2/_catalog
  $ curl  -X GET  http://localhost:5000/v2/andrew-busybox/tags/list

Let's test.
Remove the cached docker images, and then pull the new image from my local registry.

  $ docker  image  remove  busybox:1.26
  $ docker  image  remove  localhost:5000/andrew-busybox
  $ docker  pull  localhost:5000/andrew-busybox



You can read more information about private registry from https://docs.docker.com/registry/deploying/

Search image repository on private registry

You can get a image repository information from private registry like this,

  $ curl  -X GET  http://localhost:5000/v2/_catalog
  {"repositories":["andrew_busybox_0614","busybox"]}

  $ curl  -X GET  http://localhost:5000/v2/busybox/tags/list
  {"name":"busybox","tags":["17.03"]}

You can read more information about API specification from https://docs.docker.com/registry/spec/api/#listing-repositories


Delete image repository on private registry

You can delete a image repository from private registry like this,


  $ curl -X DELETE http://localhost:5000/v2/busybox/busybox/17.03



You can read more information about API specification from 





Usefull docker command

Stop all docker container

  $ docker stop $(docker ps -a -q)

Remove(Delete) all docker container

  $ docker rm $(docker ps -a -q)

Remove(Delete all docker images
  $ docker rmi $(docker images -q)

Docker process status with pretty format
  $  docker ps --no-trunc --format "table {{.Image}}\t{{.Names}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Ports}}"


Extract exposed port information from docker image
  $ docker image inspect http_svr:17.07  --format "table {{.Config.ExposedPorts}}"
    table map[10000/tcp:{} 8080/tcp:{}]


Send a process signal to docker container
  $ docker kill -s HUP $(docker ps --no-trunc --filter 'name=mysite_lbaas-1' --format "table {{.Names}}" | grep -v "NAME")

Useful alias

You can add the following alias command for docker operation

=========================================
alias docker_ps='docker ps --no-trunc --format "table {{.Names}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Ports}}"'
alias docker_rm='docker rm $(docker ps -a -q)'
alias docker_rmi='docker rmi $(docker images -q) --force'
alias docker_stop='docker stop $(docker ps -a -q)'

alias docker_monitor='while true; do date; docker_ps ; sleep 10; echo ""; echo ""; done'
=========================================




Enabling Docker Remote API

Read the web page:
  https://www.ivankrizsan.se/2016/05/18/enabling-docker-remote-api-on-ubuntu-16-04/

Modify docker.service file.
  file path: /lib/systemd/system/docker.service

  ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:4243

Run following command:
  $ systemctl daemon-reload

  $ systemctl restart docker.service


Read the web page:
  https://docs.docker.com/registry/insecure/

  file path: /etc/docker/daemon.json
  {
    "insecure-registries" : ["swarm00:5000"]
  }


Test REST API
  $ curl http://10.10.2.241:4243/images/json
  $ curl http://10.10.2.241:4243/containers/json


Dockerfile

Write following example Dockerfile:

FROM ubuntu:16.04

RUN apt-get update -y
RUN apt-get install -y apt-utils
RUN apt-get install -y net-tools vim iperf

## This EXPOSE option is not effective on swarm mode.
# EXPOSE 20001 20002 20003

CMD /usr/bin/iperf -s -p 20001 -o /tmp/andrew.log


After writing Dockerfile above, then run following command:

  $ docker build -t andrewubuntu:v3 .
  $ docker tag andrewubuntu:v3  swarm-master:5000/andrewubuntu:v3
  $ docker push  swarm-master:5000/andrewubuntu:v3
  $ docker service create --name andrewubuntu-1  --publish 30001:30001  swarm-master:5000/andrewubuntu:v3


댓글 없음:

댓글 쓰기