mirror of
https://github.com/yeasy/docker_practice.git
synced 2025-08-06 07:32:04 +00:00
Update Docker Compose file format 3
This commit is contained in:
29
compose/demo/compose-haproxy-web/docker-compose.yml
Normal file
29
compose/demo/compose-haproxy-web/docker-compose.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
version: "3"
|
||||
services:
|
||||
|
||||
weba:
|
||||
build: ./web
|
||||
expose:
|
||||
- 80
|
||||
|
||||
webb:
|
||||
build: ./web
|
||||
expose:
|
||||
- 80
|
||||
|
||||
webc:
|
||||
build: ./web
|
||||
expose:
|
||||
- 80
|
||||
|
||||
haproxy:
|
||||
image: haproxy:latest
|
||||
volumes:
|
||||
- ./haproxy:/haproxy-override
|
||||
- ./haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||
ports:
|
||||
- "80:80"
|
||||
- "70:70"
|
||||
expose:
|
||||
- "80"
|
||||
- "70"
|
32
compose/demo/compose-haproxy-web/haproxy/haproxy.cfg
Normal file
32
compose/demo/compose-haproxy-web/haproxy/haproxy.cfg
Normal file
@@ -0,0 +1,32 @@
|
||||
global
|
||||
log 127.0.0.1 local0
|
||||
log 127.0.0.1 local1 notice
|
||||
|
||||
defaults
|
||||
log global
|
||||
mode http
|
||||
option httplog
|
||||
option dontlognull
|
||||
timeout connect 5000ms
|
||||
timeout client 50000ms
|
||||
timeout server 50000ms
|
||||
|
||||
listen stats
|
||||
bind 0.0.0.0:70
|
||||
stats enable
|
||||
stats uri /
|
||||
|
||||
frontend balancer
|
||||
bind 0.0.0.0:80
|
||||
mode http
|
||||
default_backend web_backends
|
||||
|
||||
backend web_backends
|
||||
mode http
|
||||
option forwardfor
|
||||
balance roundrobin
|
||||
server weba weba:80 check
|
||||
server webb webb:80 check
|
||||
server webc webc:80 check
|
||||
option httpchk GET /
|
||||
http-check expect status 200
|
5
compose/demo/compose-haproxy-web/web/Dockerfile
Normal file
5
compose/demo/compose-haproxy-web/web/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM python:2.7
|
||||
WORKDIR /code
|
||||
ADD . /code
|
||||
EXPOSE 80
|
||||
CMD python index.py
|
68
compose/demo/compose-haproxy-web/web/index.py
Normal file
68
compose/demo/compose-haproxy-web/web/index.py
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/python
|
||||
#authors: yeasy.github.com
|
||||
#date: 2013-07-05
|
||||
|
||||
import sys
|
||||
import BaseHTTPServer
|
||||
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
||||
import socket
|
||||
import fcntl
|
||||
import struct
|
||||
import pickle
|
||||
from datetime import datetime
|
||||
from collections import OrderedDict
|
||||
|
||||
class HandlerClass(SimpleHTTPRequestHandler):
|
||||
def get_ip_address(self,ifname):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
return socket.inet_ntoa(fcntl.ioctl(
|
||||
s.fileno(),
|
||||
0x8915, # SIOCGIFADDR
|
||||
struct.pack('256s', ifname[:15])
|
||||
)[20:24])
|
||||
def log_message(self, format, *args):
|
||||
if len(args) < 3 or "200" not in args[1]:
|
||||
return
|
||||
try:
|
||||
request = pickle.load(open("pickle_data.txt","r"))
|
||||
except:
|
||||
request=OrderedDict()
|
||||
time_now = datetime.now()
|
||||
ts = time_now.strftime('%Y-%m-%d %H:%M:%S')
|
||||
server = self.get_ip_address('eth0')
|
||||
host=self.address_string()
|
||||
addr_pair = (host,server)
|
||||
if addr_pair not in request:
|
||||
request[addr_pair]=[1,ts]
|
||||
else:
|
||||
num = request[addr_pair][0]+1
|
||||
del request[addr_pair]
|
||||
request[addr_pair]=[num,ts]
|
||||
file=open("index.html", "w")
|
||||
file.write("<!DOCTYPE html> <html> <body><center><h1><font color=\"blue\" face=\"Georgia, Arial\" size=8><em>HA</em></font> Webpage Visit Results</h1></center>")
|
||||
for pair in request:
|
||||
if pair[0] == host:
|
||||
guest = "LOCAL: "+pair[0]
|
||||
else:
|
||||
guest = pair[0]
|
||||
if (time_now-datetime.strptime(request[pair][1],'%Y-%m-%d %H:%M:%S')).seconds < 3:
|
||||
file.write("<p style=\"font-size:150%\" >#"+ str(request[pair][1]) +": <font color=\"red\">"+str(request[pair][0])+ "</font> requests " + "from <<font color=\"blue\">"+guest+"</font>> to WebServer <<font color=\"blue\">"+pair[1]+"</font>></p>")
|
||||
else:
|
||||
file.write("<p style=\"font-size:150%\" >#"+ str(request[pair][1]) +": <font color=\"maroon\">"+str(request[pair][0])+ "</font> requests " + "from <<font color=\"navy\">"+guest+"</font>> to WebServer <<font color=\"navy\">"+pair[1]+"</font>></p>")
|
||||
file.write("</body> </html>")
|
||||
file.close()
|
||||
pickle.dump(request,open("pickle_data.txt","w"))
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
ServerClass = BaseHTTPServer.HTTPServer
|
||||
Protocol = "HTTP/1.0"
|
||||
addr = len(sys.argv) < 2 and "0.0.0.0" or sys.argv[1]
|
||||
port = len(sys.argv) < 3 and 80 or int(sys.argv[2])
|
||||
HandlerClass.protocol_version = Protocol
|
||||
httpd = ServerClass((addr, port), HandlerClass)
|
||||
sa = httpd.socket.getsockname()
|
||||
print "Serving HTTP on", sa[0], "port", sa[1], "..."
|
||||
httpd.serve_forever()
|
||||
except:
|
||||
exit()
|
1
compose/demo/django/.gitignore
vendored
Normal file
1
compose/demo/django/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
django_example
|
7
compose/demo/django/Dockerfile
Normal file
7
compose/demo/django/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM python:3
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
RUN mkdir /code
|
||||
WORKDIR /code
|
||||
ADD requirements.txt /code/
|
||||
RUN pip install -r requirements.txt
|
||||
ADD . /code/
|
15
compose/demo/django/docker-compose.yml
Normal file
15
compose/demo/django/docker-compose.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
version: "3"
|
||||
services:
|
||||
|
||||
db:
|
||||
image: postgres
|
||||
|
||||
web:
|
||||
build: .
|
||||
command: python3 manage.py runserver 0.0.0.0:8000
|
||||
volumes:
|
||||
- .:/code
|
||||
ports:
|
||||
- "8000:8000"
|
||||
links:
|
||||
- db
|
22
compose/demo/django/manage.py
Executable file
22
compose/demo/django/manage.py
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_example.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError:
|
||||
# The above import may fail for some other reason. Ensure that the
|
||||
# issue is really that Django is missing to avoid masking other
|
||||
# exceptions on Python 2.
|
||||
try:
|
||||
import django
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
)
|
||||
raise
|
||||
execute_from_command_line(sys.argv)
|
2
compose/demo/django/requirements.txt
Normal file
2
compose/demo/django/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Django>=1.8,<2.0
|
||||
psycopg2
|
27
compose/demo/wordpress/docker-compose.yml
Normal file
27
compose/demo/wordpress/docker-compose.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
version: "3"
|
||||
services:
|
||||
|
||||
db:
|
||||
image: mysql:5.7
|
||||
volumes:
|
||||
- db_data:/var/lib/mysql
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: somewordpress
|
||||
MYSQL_DATABASE: wordpress
|
||||
MYSQL_USER: wordpress
|
||||
MYSQL_PASSWORD: wordpress
|
||||
|
||||
wordpress:
|
||||
depends_on:
|
||||
- db
|
||||
image: wordpress:latest
|
||||
ports:
|
||||
- "8000:80"
|
||||
restart: always
|
||||
environment:
|
||||
WORDPRESS_DB_HOST: db:3306
|
||||
WORDPRESS_DB_USER: wordpress
|
||||
WORDPRESS_DB_PASSWORD: wordpress
|
||||
volumes:
|
||||
db_data:
|
Reference in New Issue
Block a user