栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

docker安装nginx

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

docker安装nginx

docker安装nginx
# 搜索镜像
https://hub.docker.com/
docker search nginx

# 下载镜像
[root@localhost docker]# docker image list
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
centos       latest    5d0da3dc9764   11 days ago   231MB
[root@localhost docker]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
07aded7c29c6: Pull complete 
bbe0b7acc89c: Pull complete 
44ac32b0bba8: Pull complete 
91d6e3e593db: Pull complete 
8700267f2376: Pull complete 
4ce73aa6e9b0: Pull complete 
Digest: sha256:06e4235e95299b1d6d595c5ef4c41a9b12641f6683136c18394b858967cd1506
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@localhost docker]# docker image list
REPOSITORY   TAG       IMAGE ID       CREATED                  SIZE
nginx        latest    f8f4ffc8092c   Less than a second ago   133MB
centos       latest    5d0da3dc9764   11 days ago              231MB
[root@localhost docker]# 
# 启动创建并启动容器
# -d 后台运行
# --name 给容器命名
# -p 映射到宿主机的指定端口:容器内部的服务端口
[root@localhost docker]# docker run -d --name nginx01 -p 3344:80 nginx
a4bc5fe767b8352e82bea52d1253f76f616e1dd13b134c94e6f9620e5511fd3d
[root@localhost docker]# docker ps
ConTAINER ID   IMAGE     COMMAND                  CREATED             STATUS             PORTS                                   NAMES
a4bc5fe767b8   nginx     "/docker-entrypoint.…"   2 seconds ago       Up 1 second        0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx01
2fecd2a6328e   centos    "/bin/bash -c 'while…"   about an hour ago   Up about an hour                                           busy_chatelet
# 测试容器的服务运行情况
[root@localhost docker]# curl localhost:3344



Welcome to nginx!



Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

进入容器查看nginx的配置
# 进入容器查看nginx的配置
[root@localhost docker]# docker ps
ConTAINER ID   IMAGE     COMMAND                  CREATED             STATUS             PORTS                                   NAMES
a4bc5fe767b8   nginx     "/docker-entrypoint.…"   9 minutes ago       Up 9 minutes       0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx01
2fecd2a6328e   centos    "/bin/bash -c 'while…"   about an hour ago   Up about an hour                                           busy_chatelet
[root@localhost docker]# docker exec -it a4bc5fe767b8 /bin/bash
root@a4bc5fe767b8:/# which nginx
/usr/sbin/nginx
root@a4bc5fe767b8:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@a4bc5fe767b8:/# cd /etc/nginx
root@a4bc5fe767b8:/etc/nginx# ls
conf.d	fastcgi_params	mime.types  modules  nginx.conf  scgi_params  uwsgi_params
root@a4bc5fe767b8:/etc/nginx# cat 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;
}
使用volume卷实现容器与宿主机共享文件
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/320505.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号