docker pull nginx
直接pull 默认是获取最新版的;
mkdir ~/nginx
cd ~/nginx
mkdir conf
docker run -it --name nginx -p 80:80 nginx
docker ps
//拿到容器id执行下面的copy配置文件命令,也可以手动编写,这样就不用先启动nginx容器了。 docker cp 13afb35cbc98:/etc/nginx/nginx.conf ./nginx/conf
docker stop nginx
docker run -id -p 80:80--name c_name -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \
-v $PWD/logs:/var/log/nginx \
-v $PWD/html:/usr/share/nginx/html nginx
参数说明:
-id 后台运行,需要使用exec进入容器,退出后容器不会关闭;对应 -it,退出容器后就会关闭;
-p 端口映射,将容器端口(冒号后面)映射到宿主机端口上;
-v 挂载容器的数据卷
原文:https://www.cnblogs.com/xp2h/p/12420618.html