docker 创建nginx容器部署前端服务

1、搜索nginx镜像

docker search nginx

2、拉取镜像

docker pull nginx名称

3、创建test镜像

 docker run --name nginx-test -p 8080:80 -d nginx

4、访问宿主ip和端口,查看 nginx

5、从nginx-test测试容器中拷贝文件到宿主机

docker cp nginx-test:/etc/nginx/nginx.conf /home/nginx/copadmin

 5、nginx目录挂在,必须在宿主机上有nginx.conf 文件才可以挂在,所以在宿主进上创建  /nginx/config/nginx.conf配置文件,配置文件如下

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/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 /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;


server {
listen 8081;
server_name 10.9.53.58;

#charset koi8-r;

location / {
proxy_pass http://www.badu.com;
#root /home/copfront/copfront.admin/dist;
#index index.html index.htm;
}

#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 /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}


}

 

}

6、构建镜像,并目录挂载

docker run --name cop.admin.web -p 8001:80 -v /home/nginx/copadmin/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx -v /home/copfront/copfront.admin/:/usr/share/html -d nginx

7、将打包好的前端页面直接放到对应的copfront.admin文件夹内就可以了

8、重启docker 容器

原文地址:https://www.cnblogs.com/cyit/p/15152401.html