docker安装nginx
安装以及启动
docker pull nginx
docker run -d -p 80:80 --name kaka-nginx --net host -v /kaka-data/nginx/www:/usr/share/nginx/html -v /kaka-data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /kaka-data/nginx/logs:/var/log/nginx --privileged nginx
出现的问题
执行docker run的时候报的错
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/kaka-data/nginx/nginx.conf" to rootfs at "/etc/nginx/nginx.conf" caused: mount through procfd: 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.
解决的办法
- 先暂时把-v /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf 去掉
- 再次启动docker run -d -p 80:80 --name kaka-nginx --net host -v /kaka-data/nginx/www:/usr/share/nginx/html -v /kaka-data/nginx/logs:/var/log/nginx --privileged nginx
- 发现可以成功启动
- 然后进入nginx容器把配置文件复制到 /kaka-data/nginx/conf/ 里面
第一步:docker exec -it kaka-nginx /bin/bash (进入容器 获取文件)
第二步:cd /etc/nginx/ (这里主要获取配置文件路径的)
第三步:exit
第四步:cd /docker/nginx/conf/
第五步:docker cp 2ae68080aaca:/etc/nginx/nginx.conf .
ps:文件copy成功后 把nginx容器先删除掉
第六步:docker rm kaka-nginx
第七步:docker run -d -p 80:80 --name kaka-nginx --net host -v /kaka-data/nginx/www:/usr/share/nginx/html -v /kaka-data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /kaka-data/nginx/logs:/var/log/nginx --privileged nginx
验证访问
在/kaka-data/nginx/www/里面新建index.html即可,然后再次访问