Docker安装配置nginx

docker安装配置nginx

  1. docker拉取nginx镜像
    docker pull nginx
    
  2. 创建配置映射目录
    mkdir -p /usr/local/nginx/conf
    mkdir -p /usr/local/nginx/log
    mkdir -p /usr/local/nginx/html
    
  3. 先运行一次docker镜像,复制docker内配置文件到服务器
    docker run --name nginx -p 8000:80 -d nginx
    docker cp nginx:/etc/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf
    docker cp nginx:/etc/nginx/conf.d /usr/local/nginx/conf/conf.d
    docker cp nginx:/usr/share/nginx/html /usr/local/nginx
    
  4. 删除运行的nginx容器
    docker stop nginx
    docker rm nginx
    
  5. 正式运行nginx容器

    服务器安全组别忘记开放8000端口

    docker run -p 8000:80 --name nginx -v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/conf/conf.d:/etc/nginx/conf.d -v /usr/local/nginx/log:/var/log/nginx -v /usr/local/nginx/html:/usr/share/nginx/html -d nginx:latest
    

你可能感兴趣的:(后端,nginx,docker,运维)