APACHE镜像的DOCKERFILE
[root@cons7s s1]# cat dockerfile
FROM docker.io/centos:centos6
MAINTAINER bcdgptv@21cn.com
RUN yum install -y httpd net-tools iputils
RUN sed 's/#ServerName www.example.com:80/ServerName www.bcdgptv.com.cn/g' /etc/httpd/conf/httpd.conf
EXPOSE 80
CMD ["/usr/sbin/httpd","-DFOREGROUND"
[root@cons7s s1]# docker build -t centos:http .
NGINX镜像的DOCKERFILE
[root@cons7s s2]# cat dockerfile
#images of nginx
FROM docker.io/centos:centos6
RUN yum install -y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel
RUN useradd -M -s /sbin/nologin nginx
ADD http://nginx.org/download/nginx-1.6.2.tar.gz .
RUN tar zxvf nginx-1.6.2.tar.gz
RUN mkdir -p /usr/local/nginx
RUN cd nginx-1.6.2 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module && make && make install
RUN ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
copy nginx.conf /usr/local/nginx/conf/nginx.conf
expose 80
CMD ["nginx"]
同一目录建立nginx.conf
[root@cons7s s2]# cat nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream apaches{
server Apache1:80 weight=1;
server Apache2:80 weight=1;
server Apache3:80 weight=1;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://apaches;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
daemon off;
构建镜像
[root@cons7s s2]# docker build -t centos:nginx .
安装docker-compose
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install docker-compose --ignore-installed requests
docker-compose.yml 文件内容:
[root@cons7s docker-nginx]# cat docker-compose.yml
Apache1:
image: centos:http
expose:
- 80
Apache2:
image: centos:http
expose:
- 80
Apache3:
image: centos:http
expose:
- 80
nginx:
image: centos:nginx
links:
- Apache1
- Apache2
- Apache3
ports:
- "8000:80"
[root@cons7s docker-nginx]# cat docker-compose.yml
Apache1:
image: centos:http
expose:
- 80
Apache2:
image: centos:http
expose:
- 80
Apache3:
image: centos:http
expose:
- 80
nginx:
image: centos:nginx
links:
- Apache1
- Apache2
- Apache3
ports:
- "8000:80"
[root@cons7s docker-nginx]# cat nginx/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream apaches{
server Apache1:80 weight=1;
server Apache2:80 weight=1;
server Apache3:80 weight=1;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://apaches;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
[root@cons7s docker-nginx]# docker-compose up -d
[root@cons7s docker-nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55fe5edfb3e9 centos:nginx "nginx" 21 minutes ago Up 21 minutes 0.0.0.0:8000->80/tcp docker-nginx_nginx_1
98d200ba1494 centos:http "/usr/sbin/httpd -..." 21 minutes ago Up 21 minutes 80/tcp docker-nginx_Apache2_1
acd4c969393f centos:http "/usr/sbin/httpd -..." 21 minutes ago Up 21 minutes 80/tcp docker-nginx_Apache1_1
1b97091f017e centos:http "/usr/sbin/httpd -..." 21 minutes ago Up 21 minutes 80/tcp docker-nginx_Apache3_1