docker导出日志到本地的方法是什么
264
2022-10-21
使用docker运行nginx
方法一、通过 Dockerfile构建
创建Dockerfile
首先,创建目录nginx,用于存放后面的相关东西。
runoob@runoob:~$ mkdir -p ~/nginx/~/nginx/logs ~/nginx/conf
debian:jessieMAINTAINER NGINX Docker Maintainers "docker-maint@nginx.com"ENV NGINX_VERSION 1.10.1-1~jessieRUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \ && echo "deb jessie nginx" >> /etc/apt/sources.list \ && apt-get update \ && apt-get install --no-install-recommends --no-install-suggests -y \ ca-certificates \ nginx=${NGINX_VERSION} \ nginx-module-xslt \ nginx-module-geoip \ nginx-module-image-filter \ nginx-module-perl \ nginx-module-njs \ gettext-base \ && rm -rf /var/lib/apt/lists/*# forward request and error logs to docker log collectorRUN ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.logEXPOSE 80 443CMD ["nginx", "-g", "daemon off;"]
通过Dockerfile创建一个镜像,替换成你自己的名字
docker build -t nginx .
创建完成后,我们可以在本地的镜像列表里查找到刚刚创建的镜像
runoob@runoob:~/nginx$ docker images nginxREPOSITORY TAG IMAGE ID CREATED SIZEnginx latest 555bbd91e13c 3 days ago 182.8 MB
方法二、docker pull nginx
查找Docker Hub上的nginx镜像
runoob@runoob:~/nginx$ docker search nginxNAME DESCRIPTION STARS OFFICIAL AUTOMATEDnginx Official build of Nginx. 3260 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 674 [OK]richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 207 [OK]million12/nginx-php Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS... 67 [OK]maxexcloo/nginx-php Docker framework container with Nginx and ... 57 [OK]webdevops/php-nginx Nginx with PHP-FPM 39 [OK]h3nrik/nginx-ldap NGINX web server with LDAP/AD, SSL and pro... 27 [OK]bitnami/nginx Bitnami nginx Docker Image 19 [OK]maxexcloo/nginx Docker framework container with Nginx inst... 7 [OK]...
这里我们拉取官方的镜像
runoob@runoob:~/nginx$ docker pull nginx
等待下载完成后,我们就可以在本地镜像列表里查到REPOSITORY为nginx的镜像。
使用nginx镜像
运行容器
runoob@runoob:~/nginx$ docker run -p 80:80 --name mynginx -v $PWD/-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/ -d nginx 45c89fab0bf9ad643bc7ab571f3ccd65379b844498f54a7c8a4e7ca1dc3a2c1erunoob@runoob:~/nginx$
命令说明:
-p 80:80:将容器的80端口映射到主机的80端口
–name mynginx:将容器命名为mynginx
-v $PWD/$PWD/conf/nginx.conf:/etc/nginx/nginx.conf:将主机中当前目录下的nginx.conf挂载到容器的/etc/nginx/nginx.conf
-v $PWD/logs:/docker psCONTAINER ID IMAGE COMMAND PORTS NAMES45c89fab0bf9 nginx "nginx -g 'daemon off" ... 0.0.0.0:80->80/tcp, 443/tcp mynginxf2fa96138d71 tomcat "catalina.sh run" ... 0.0.0.0:81->8080/tcp tomcat
通过浏览器访问
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~