拉取镜像

 docker pull nginx:latest

加速配置

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://gij24fi0.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

启动

docker run --name nginx -d -v $PWD/nginx/nginx.conf:/etc/nginx/nginx.conf -v $PWD/nginx/html:/usr/share/nginx/html -v $PWD/nginx/log:/var/log/nginx -p 8080:80 nginx

报错

docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\\"/root/nginx/nginx.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/32497fd9f5b1826a3e28e4aedf6da6c7a6723d8e225270449468f98197b7cebe/merged\\\" at \\\"/var/lib/docker/overlay2/32497fd9f5b1826a3e28e4aedf6da6c7a6723d8e225270449468f98197b7cebe/merged/etc/nginx/nginx.conf\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
ERRO[0000] error waiting for container: context canceled 

将主机中的nginx.conf文件夹删除 并创建同名问文件
重新启动

docker start nginx

启动失败

2020/03/19 12:30:20 [emerg] 1#1: no "events" section in configuration
nginx: [emerg] no "events" section in configuration

vim nginx.conf
添加配置

events {
  worker_connections  1024;  ## Default: 1024
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

        server{
                listen 80;
                server_name nginx;   #你的serverName
                root /usr/share/nginx/html;
                index index.html;
        }

}