1
2
docker cp <containerId>:/file/path/within/container /host/path/target
 
cs


Posted by 사용자 guru_k

댓글을 달아 주세요

Nginx on Docker

Docker 2017. 3. 30. 13:14

Run Nginx on Docker 


1. Create Dockerfile

1
2
3
4
FROM nginx
COPY html /usr/share/nginx/html # html directory of content
ADD nginx.conf /etc/nginx/nginx.conf # nignx config file
CMD ["nginx", "-g", "daemon off;"]
cs


2.Create nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
user nobody nogroup;
worker_processes auto;          # auto-detect number of logical CPU cores
 
events {
  worker_connections 512;       # set the max number of simultaneous connections (per worker process)
}
 
http {
  server {
    listen *:80;                # Listen for incoming connections from any interface on port 80
    server_name "";             # Don't worry if "Host" HTTP Header is empty or not set
    root /usr/share/nginx/html; # serve static files from here
  }
}
cs


3. Create /html/index.html for test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
html>
  <head>
    <title>Sample "Hello, World" Application</title>
  </head>
  <body bgcolor=white>
 
    <table border="0" cellpadding="10">
      <tr>
        <td>
          <h1>Sample "Hello, World" Application</h1>
        </td>
      </tr>
    </table>
 
    <p>This is the home page for the HelloWorld Web application. </p>
  </body>
</html>
cs



3. docker build

1
docker build -t docker-nginx .
cs


4. Check docker image

1
2
3
$ docker images
REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
docker-nginx                               latest              c86e2b339c31        About an hour ago   182.5 MB
cs


5. docker run

1
docker run --name docker-nginx -d -p 80:80 docker-nginx
cs


6. Connect [host_ip or localhost]:8080 and Check




 


Posted by 사용자 guru_k

댓글을 달아 주세요

Load Balancing with HAProxy on Docker


Setup


HAProxy + Socket.io + Node

 


HAProxy Config 


haproxy.cfg


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
global
  maxconn 4096
 
defaults
  mode http
  balance roundrobin
  option redispatch
  option forwardfor
  timeout connect 5s
  timeout queue 5s
  timeout client 50s
  timeout server 50s
 
listen stats
  bind  *:1936
  mode  http
  stats enable
  stats uri /stats
  stats auth guest:guest
  stats refresh 5s
 
frontend http-in
  bind *:8000
 
# check request ws acl
  acl backend_ws path_beg /socket.io
  acl backend_ws hdr(Upgrade) -i webSocket
  acl backend_ws hdr_beg(Host) -i ws
 
# if it is ws request , use websockets
  use_backend websockets if is_websocket
# if it is http request, use webservers
  default_backend servers 
 
backend servers # web server
  server server1 [address]:[port] check
#example
#server server1 172.17.0.10:8080 check
 
backend websockets # socket server
  balance source # if use balance to roundrobin, you have to use stick option
  option http-server-close
  option forceclose
  server ws-server1 [address]:[port] maxconn 30000 weight 1 maxconn 1024 check
#example
#server ws-server1 172.17.0.1:80 maxconn 30000 weight 1 maxconn 1024 check
  #server ws-server2 172.17.0.2:80 maxconn 30000 weight 1 maxconn 1024 check
  #server ws-server3 172.17.0.3:80 maxconn 30000 weight 1 maxconn 1024 check
cs


Docker run HAProxy


1
docker run -d -p 1936:1936 -p 8000:8000 --name docker-haproxy my-haproxy
cs


reference - http://mydreamisthebestcooder.tistory.com/78


Test

Load test

1. Use websocket-bench


1
$ websocket-bench -a 100 -c 20 ws://127.0.0.1:8000
cs


https://github.com/M6Web/websocket-bench


2. Use Socket.io test client

http://amritb.github.io/socketio-client-tool/



Posted by 사용자 guru_k

댓글을 달아 주세요

HAProxy with Docker

Docker 2017. 3. 24. 22:14

Use HAProxy with Docker


1. Create Dockerfile for HAProxy Build with Docker 

1
2
FROM haproxy:1.7 // Set HAProxy version
ADD haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
cs


2. Docker build using Dockerfile created

1
docker build -t my-haproxy .
cs


3.  After you build Dockerfile, you can find docker images that is my-haproxy 

1
2
3
$ docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
my-haproxy                              latest              98f53e224010        5 hours ago         134.9 MB
cs


4. To create HAProxy you should make haproxy.cfg that is configure file for haproxy. 

For test I already created two nodes

haproxy.cfg are contained health check 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
global
 
  log 127.0.0.1  local0
  log 127.0.0.1  local1 notice
  maxconn  8192
 
defaults
  balance roundrobin
  log     global
  mode    tcp
  option  tcplog
  option  redispatch
  option  log-health-checks
  retries 5
  maxconn 8192
  timeout connect 50s
  timeout client  500s
  timeout server  500s
 
listen stats
  bind  *:1936
  mode  http
  stats enable
  stats uri /stats
  stats auth guest:guest
  stats refresh 5s
 
listen web
bind *:80 mode http balance roundrobin server web1 172.17.0.8:7777 check server web2 172.17.0.9:7778 check
cs


  • stats
    • Set haproxy monitoring
    • You can connect [host_ip]:1936/stats and see haproxy web ui
    • auth - account ID / account PW
  • web
    • Bind 80 port.
    • balance mode is roundrobin.
    • health check for web1, web2.

5. Use haproxy.cfg that you set to run the docker.
1
docker run -d -p 1936:1936 -p 80:80 --name docker-haproxy my-haproxy
cs

6. If docker is run well, You can see the stats UI.
Through [host_ip]:1936/stats, You can see web ui below.




Posted by 사용자 guru_k

댓글을 달아 주세요

docker-compose 를 업그레이드 이 후


docker-compose up 을 할 경우


1
ERROR: The engine version is lesser than the minimum required by compose. Your current project requires a Docker Engine of version 1.10.0 or superior.
cs


위와 같이 또 다른 에러가 발생할 수 있다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ docker version
Client:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.4.3
 Git commit:   a34a1d5
 Built:        Fri Nov 20 17:56:04 UTC 2015
 OS/Arch:      darwin/amd64
 
Server:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.4.3
 Git commit:   a34a1d5
 Built:        Fri Nov 20 17:56:04 UTC 2015
 OS/Arch:      linux/amd64
APSEONOTE131:local gkwak$ docker-
cs


docker version 을 살펴보면 1.9.1이다.


docker version 이 1.10.0 이거나 이상이어야 한다.


아래 커맨드를 사용하여 docker를 업그레이드 해주자.


1
$ docker-machine upgrade default
cs



Posted by 사용자 guru_k

댓글을 달아 주세요

docker-compose 버젼이 낮은상태에서 version: '2' 를 사용할 경우



1
ERROR: In file './docker-compose.yml' service 'version' doesn't have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.
cs


위와 같은 에러가 발생한다.


그럴땐 docker-compose를 최신버젼으로 업데이트하자.


1
curl -L https://github.com/docker/compose/releases/download/1.6.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
cs



참고 : https://docs.docker.com/compose/install/

Posted by 사용자 guru_k

댓글을 달아 주세요