Docker 安装 Nginx
2018-11-30 dingshangchao 服务器
1.移除旧版本
$ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine
2.安装一些必要的系统工具:
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
3.添加软件源信息:
$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4.更新 yum 缓存: sudo yum makecache fast
5.安装 Docker-ce:
sudo yum -y install docker-ce6.启动 Docker 后台服务
sudo systemctl start docker
7.拉取镜像
$ docker pull nginx
8.新建文件夹nginx 下新建conf logs www三个文件夹 conf下拷贝进nginx.conf
9.运行容器,为方便修改和查看要把容器内nginx的根目录、日志和配置挂载到本地
$docker run -p 80:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx
10.ip可访问ps: 如果没有nginx.conf文件或者文件目录错误会报错:
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 \\\"/home/testuser/docker/nginx/conf/conf/nginx.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/ec94b1923f5ffed2e2de446aa72e46f417617034de95a50c3874478fb3c3e8be/merged\\\" at \\\"/var/lib/docker/overlay2/ec94b1923f5ffed2e2de446aa72e46f417617034de95a50c3874478fb3c3e8be/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.
要先停止并移除容器
$ docker stop mynginx$ docker rm mynginx 再重新run
« 虎课网
|
php---COW机制»