拉取docker中nginx镜像

docker pull nginx

1、本地创建nginx挂载路径

mkdir /usr/local/docker/nginx/conf

mkdir /usr/local/docker/nginx/conf/conf.d

mkdir /usr/local/docker/nginx/html

mkdir /usr/local/docker/nginx/conf

2、简单启动一个nginx服务(仅用来复制配置文件,复制完即删除此容器)

docker run --name nginx_test -d -p 80:80 nginx

3、复制nginx配置文件到宿主机

docker cp nginx_test:/etc/nginx/conf.d /usr/local/docker/nginx/conf/conf.d/
docker cp nginx_test:/etc/nginx/nginx.conf usr/local/docker/nginx/conf/
docker cp nginx_test:/usr/share/nginx/html/ /usr/local/docker/nginx/html/

4、移除容器

docker rm -f nginx_test

5、创建nginx网络

docker network create nginx_network

docker run --name my_nginx -p 80:80 -v /usr/local/docker/nginx/conf/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /usr/local/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/docker/nginx/html/:/usr/share/nginx/html/ -v /usr/local/docker/nginx/logs/:/var/log/nginx/ --privileged=true -d --restart=always nginx

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐