Skip to content

Commit

Permalink
chapter4
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Xiao <[email protected]>
  • Loading branch information
xiaopeng163 committed Jan 21, 2018
1 parent e7a68f9 commit db04447
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vagrant
42 changes: 42 additions & 0 deletions chapter3/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.6.0"

boxes = [
{
:name => "docker-host",
:eth1 => "192.168.205.10",
:mem => "1024",
:cpu => "1"
}
]

Vagrant.configure(2) do |config|

config.vm.box = "centos/7"
config.vm.synced_folder ".", "/home/docker-host/"
boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.hostname = opts[:name]
config.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = opts[:mem]
v.vmx["numvcpus"] = opts[:cpu]
end
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", opts[:mem]]
v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
end
config.vm.network :private_network, ip: opts[:eth1]
end
end
config.vm.provision "shell", inline: <<-SHELL
# https://docs.docker.com/engine/installation/linux/docker-ce/centos/
# https://github.com/docker/docker-install
sudo yum install -y git vim gcc glibc-static telnet
git clone sudo yum install -y git vim gcc glibc-static telnet
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
sudo systemctl start docker
SHELL
end
54 changes: 54 additions & 0 deletions chapter4/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.6.0"

boxes = [
{
:name => "docker-node1",
:eth1 => "192.168.205.10",
:mem => "1024",
:cpu => "1",
:port => "8888"
},
{
:name => "docker-node2",
:eth1 => "192.168.205.11",
:mem => "1024",
:cpu => "1",
:port => "9999"
}
]

Vagrant.configure(2) do |config|

config.vm.box = "centos/7"

boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.hostname = opts[:name]
config.vm.network "forwarded_port", guest: 80, host: opts[:port]
config.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = opts[:mem]
v.vmx["numvcpus"] = opts[:cpu]
end

config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", opts[:mem]]
v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
end

config.vm.network :private_network, ip: opts[:eth1]
end
end

config.vm.provision "shell", inline: <<-SHELL
# https://docs.docker.com/engine/installation/linux/docker-ce/centos/
# https://github.com/docker/docker-install
sudo yum install -y git vim gcc glibc-static telnet
git clone sudo yum install -y git vim gcc glibc-static telnet
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
sudo systemctl start docker
SHELL
end
7 changes: 7 additions & 0 deletions chapter4/flask-redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:2.7
LABEL maintaner="Peng Xiao [email protected]"
COPY . /app
WORKDIR /app
RUN pip install flask redis
EXPOSE 5000
CMD [ "python", "app.py" ]
17 changes: 17 additions & 0 deletions chapter4/flask-redis/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from flask import Flask
from redis import Redis
import os
import socket

app = Flask(__name__)
redis = Redis(host=os.environ.get('REDIS_HOST', '127.0.0.1'), port=6379)


@app.route('/')
def hello():
redis.incr('hits')
return 'Hello Container World! I have been seen %s times and my hostname is %s.\n' % (redis.get('hits'),socket.gethostname())


if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)

0 comments on commit db04447

Please sign in to comment.