mkdir /opt/docker-file/redis&& cd /opt/docker-file/redis
vim Dockerfile,
FROMcentos
MAINTAINERsf 843248880@qq.com
ENVREFRESHED 2016-09-28
RUN yum-y install wget
RUN if [-f /etc/yum.repos.d/CentOS-Base.repo ];then mv/etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup;fi
RUN wget-O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo
RUN if [-f /etc/yum.repos.d/epel.repo ];then /etc/yum.repos.d/epel.repo/etc/yum.repos.d/epel.repo.backup;fi
RUN if [-f /etc/yum.repos.d/epel-testing.repo ];then mv/etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup;fi
RUN wget-O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
RUN yumclean all
RUN yummakecache
RUN yum-y update
RUN yum-y install redis
EXPOSE6379
ENTRYPOINT ["/usr/sbin/redis-server" ]
3. docker build –t redis/sinatra_test.
4. dockerrun –d –name redis redis/sinatra_test #注意,这里没有指定端口
5. vim /opt/docker-file/sinatra/webapp/lib/app.rb,与redis建立连接,内容见下,
require"rubygems"
require"sinatra"
require"json"
require"redis"
class App < Sinatra::Application
redis = Redis.new(:host => 'db', :port => '6379')
set :bind, '0.0.0.0'
get '/' do
"<h1>DockerBook Test Redis-enabled Sinatraapp</h1>"
end
get '/json' do
params = redis.get "params"
params.to_json
end
post '/json/?' do
redis.set "params", [params].to_json
params.to_json
end
end
6. docker run -p 4567 --name webapp -d--link redis:db -v /opt/docker-file/sinatra/webapp:/opt/webappzsc/sinatra_ubuntu
#--link:直接把两个容器链接起来,此时webapp这个容器能访问redis容器的所有开放端口,所以刚才构建redis容器时没有指定端口。
7. curl -i -H 'Accept: application/json' -d 'name1=123&age1=456' http://localhost:32779/json
然后curl -i http://localhost:32779/json就能取到redis里的内容了。
4.docker构建jenkins
mkdir –p /opt/docker-file/jenkins&& cd /opt/docker-file/jenkins
mkdir –p /opt/docker-file/Jekyll&& cd /opt/docker-file/jekyll
vim Dockerfile
FROMcentos
MAINTAINERsf 843248880@qq.com
ENVREFRESHED 16_10_09
RUN yum-y install wget
RUN wget-O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo
RUN wget-O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
RUN yumclean all
RUN yummakecache
RUN yum-y install make nodejs ruby ruby-devel gcc gcc-c++
RUN gemsources --remove https://rubygems.org/
RUN gemsources -a https://ruby.taobao.org/
RUN geminstall jekyll
VOLUME/data
VOLUME/var/www/html
WORKDIR/data
ENTRYPOINT ["jekyll","build","--destination=/var/www/html" ]
3. docker build –t Jekyll/centos .
5.2 nginx镜像
mkdir –p /opt/docker-file/nginx_jekyll&& cd /opt/docker-file/nginx_jekyll