Docker_nginx

1.在文件夹Dockerfile下建立Dockerfile文件

vim Dockerfile
输入i,然后输入下边内容
FROM nginx
COPY index.html /usr/share/nginx/html

2.同目录下建立index.html
用vscode打开index.html文件,输入!,点击enter,生成html模板,随便输入点内容

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> nginx 1 </title>
</head>
<body>
    <h1> nginx1 server </h1>
</body>
</html>

3.文件夹下内容确认

sixdog@192 Dockerfile % ls
Dockerfile	index.html

4.构建镜像

sixdog@192 Dockerfile % docker build -t nginx:01 .
[+] Building 16.4s (7/7) FINISHED                                                                                                              
 => [internal] load build definition from Dockerfile                                                                                      0.0s
 => => transferring dockerfile: 91B                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                         0.0s
 => => transferring context: 2B                                                                                                           0.0s
 => [internal] load metadata for docker.io/library/nginx:latest                                                                          16.2s
 => CACHED [1/2] FROM docker.io/library/nginx@sha256:644a70516a26004c97d0d85c7fe1d0c3a67ea8ab7ddf4aff193d9f301670cf36                     0.0s
 => [internal] load build context                                                                                                         0.0s
 => => transferring context: 414B                                                                                                         0.0s
 => [2/2] COPY index.html /usr/share/nginx/html                                                                                           0.0s
 => exporting to image                                                                                                                    0.0s
 => => exporting layers                                                                                                                   0.0s
 => => writing image sha256:392284f7aa91fbcf2d35884f7045f300a073ea63dc1694aaa72b41f83abdaa75                                              0.0s
 => => naming to docker.io/library/nginx:01   

5.运行容器

sixdog@192 Dockerfile % docker run --rm -d -p 8080:80 nginx:01
56c8b2853d55995195f4c019b037a9d5c20eaeb588766b7b8e31424deeee1dc5

6.查看容器状态

sixdog@192 Dockerfile % docker ps 
CONTAINER ID   IMAGE      COMMAND                  CREATED              STATUS              PORTS                  NAMES
56c8b2853d55   nginx:01   "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:8080->80/tcp   cranky_chaum

7.在浏览器打开网址:http://localhost:8080/
在这里插入图片描述
8.查看容器名字

sixdog@192 Dockerfile % docker ps   
CONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS         PORTS                  NAMES
d5db4c8d4b3e   nginx:01   "/docker-entrypoint.…"   3 minutes ago   Up 3 minutes   0.0.0.0:8080->80/tcp   cranky_chaum

9.进入容器

sixdog@192 Dockerfile % docker exec -it cranky_chaum /bin/bash
root@d5db4c8d4b3e:/# pwd
/
root@d5db4c8d4b3e:/# ls -lt
total 84
drwxr-xr-x   1 root root 4096 Nov  3 14:16 run
drwxr-xr-x   5 root root  340 Nov  3 14:16 dev
dr-xr-xr-x  13 root root    0 Nov  3 14:16 sys
dr-xr-xr-x 192 root root    0 Nov  3 14:16 proc
drwxr-xr-x   1 root root 4096 Nov  3 14:16 etc
drwxr-xr-x   1 root root 4096 Oct 12 02:03 docker-entrypoint.d
drwxrwxrwt   1 root root 4096 Oct 12 02:03 tmp
drwxr-xr-x   1 root root 4096 Oct 12 02:03 lib
-rwxrwxr-x   1 root root 1202 Oct 12 02:03 docker-entrypoint.sh
drwxr-xr-x   2 root root 4096 Oct 11 00:00 bin
drwxr-xr-x   2 root root 4096 Oct 11 00:00 lib64
drwxr-xr-x   2 root root 4096 Oct 11 00:00 media
drwxr-xr-x   2 root root 4096 Oct 11 00:00 mnt
drwxr-xr-x   2 root root 4096 Oct 11 00:00 opt
drwx------   2 root root 4096 Oct 11 00:00 root
drwxr-xr-x   2 root root 4096 Oct 11 00:00 sbin
drwxr-xr-x   2 root root 4096 Oct 11 00:00 srv
drwxr-xr-x   1 root root 4096 Oct 11 00:00 usr
drwxr-xr-x   1 root root 4096 Oct 11 00:00 var
drwxr-xr-x   2 root root 4096 Oct  3 09:00 boot
drwxr-xr-x   2 root root 4096 Oct  3 09:00 home
root@d5db4c8d4b3e:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@d5db4c8d4b3e:/# cd /usr/share/nginx/html
root@d5db4c8d4b3e:/usr/share/nginx/html# ls
50x.html  index.html
root@d5db4c8d4b3e:/usr/share/nginx/html# cat index.html 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> nginx 1 </title>
</head>
<body>
    <h1> nginx1 server </h1>
</body>
</html>root@d5db4c8d4b3e:/usr/share/nginx/html# 

10.查看配置文件

root@d5db4c8d4b3e:/# cd /etc/nginx/
root@d5db4c8d4b3e:/etc/nginx# ls -lt
total 32
drwxr-xr-x 1 root root 4096 Nov  3 14:16 conf.d
lrwxrwxrwx 1 root root   22 Sep  7 15:38 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root  648 Sep  7 15:38 nginx.conf
-rw-r--r-- 1 root root 1007 Sep  7 15:21 fastcgi_params
-rw-r--r-- 1 root root 5290 Sep  7 15:21 mime.types
-rw-r--r-- 1 root root  636 Sep  7 15:21 scgi_params
-rw-r--r-- 1 root root  664 Sep  7 15:21 uwsgi_params
root@d5db4c8d4b3e:/etc/nginx# 
root@d5db4c8d4b3e:/etc/nginx# cd conf.d/
root@d5db4c8d4b3e:/etc/nginx/conf.d# ls
default.conf
root@d5db4c8d4b3e:/etc/nginx/conf.d# cat default.conf 
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

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

    # 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;
    #}
}

root@d5db4c8d4b3e:/etc/nginx/conf.d# cd..
root@d5db4c8d4b3e:/etc/nginx# ls
conf.d	fastcgi_params	mime.types  modules  nginx.conf  scgi_params  uwsgi_params
root@d5db4c8d4b3e:/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;
}
root@d5db4c8d4b3e:/etc/nginx# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值