docker run -d -p 8080:80 --name nginx nginx:1.12
docker exec -it nginx bash
root@5096ffe0b74f:/etc/nginx# cat nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; # 包含config.d/下的配置文件 include /etc/nginx/conf.d/*.conf; }
root@5096ffe0b74f:/etc/nginx# cd conf.d/ root@5096ffe0b74f:/etc/nginx/conf.d# ls default.conf
default.conf的内容:html
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
我就简单修改为一句话。nginx
欢迎来到Nginx!
docker commit -m="update index.html" -a="Howinfun" nginx(容器ID或容器名) howinfun/nginx:1.0(建立的目标镜像名)
docker@default:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE howinfun/nginx 1.0 03fd1aac0888 12 minutes ago 155MB nginx 1.12 4037a5562b03 17 months ago 108MB ubuntu 15.10 9b9cb95443b5 3 years ago 137MB
docker run -d -p 8080:80 --name=hyfnginx howinfun/nginx:1.0
docker port hyfnginx -> 返回端口号 docker ps -> PORTS有端口号的信息
由于我是在Windows上安装Docker,因此咱们访问前必须查看default虚拟机的ip,打开Git Bash,输入命令:docker
Howinfun@LAPTOP-BHT98468 MINGW64 ~/Desktop $ docker-machine ip default 192.168.99.100 -> default虚拟机的IP地址
那么若是咱们想经过Windows系统直接访问呢,那么可在Oracle VM VirtualBox配置端口转发。最后,咱们能够访问192.168.99.100:8080或者127.0.0.1:8080均可以访问到nginx的主页。
ubuntu