markdown #Docker容器,基本nginx服务器暴露端口 - Window Guide.md

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown #Docker容器,基本nginx服务器暴露端口 - Window Guide.md相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>
	<head>
		<title>Some static content</title>
	</head>
	<body>
		Looks good!
	</body>
</html>
events {
  worker_connections 1024;
}

http {
	include mime.types;
	sendfile on;
	tcp_nopush on;
	index index.html;

	server {
		listen 80;
		root /usr/share/nginx/html;
	}
}
# Docker container with basic nginx server that has exposed ports on Windows Guide/Tutorial


### Environment

Windows 10 with Anniversary update

Using Docker Toolbox (uses boot2docker VirtualBox machines)

```
docker -v
Docker version 1.12.0, build 8eab29e
```


### Instructions

 1. `docker-machine create --driver virtualbox some-box` or `docker-machine start some-box` if you already created the machine
 1. `docker-machine env some-box` (be sure the run the command it spits out at the end of that output to actual setup your env
 1. Setup the nginx container

    ```
    docker run -d -v //c/Users/MLM/Downloads/static-server-stuff/public:/usr/share/nginx/html:ro  -v //c/Users/MLM/Downloads/static-server-stuff/nginx.conf:/etc/nginx/nginx.conf:ro -p 5031:80 --name some-nginx nginx
    ```

    - `-d`: "Run container in background and print container ID", https://docs.docker.com/engine/reference/commandline/run/#options
    - `-v //c/Users/MLM/Downloads/static-server-stuff/public:/usr/share/nginx/html:ro`: Sets up a shared read-only(`:ro`) volume mapping your Windows host directory, `C:\Users\MLM\Downloads\static-server-stuff\public`, to `/usr/share/nginx/html` in the container
    - `-v //c/Users/MLM/Downloads/static-server-stuff/nginx.conf:/etc/nginx/nginx.conf:ro`: Sets up a shared read-only(`:ro`) volume mapping your Windows host file, `C:\Users\MLM\Downloads\static-server-stuff\nginx.conf`, to `/etc/nginx/nginx.conf` in the container
    - `-p 5031:80`: Maps port Docker machines port `5031` to the containers port `80` (accessible on `docker-machine ip some-box`, not `localhost`)
    - `--name some-nginx`: Adds a name to your container so you can better distinguish it (it can be anything)
    - `nginx`: The image name to use
1. Run `docker-machine ip some-box` to get the IP we can access
1. Visit the IP we just got above with the port we specified on the container, perhaps something like `http://192.168.99.100:5031`


### Teardown

 1. `docker ps --all` will show you all of the containers in the machine
 1. You can stop a container by using the ID from the command above, `docker stop e4926128afab`
 1. You can remove a container by using the ID from the command above `docker rm e4926128afab`

---

 1. `docker-machine ls` will show you all of the machines
 1. To stop the Docker machine `docker-machine stop some-box`
 1. To remove the whole Docker machine `docker-machine rm -f some-box`


### Troubleshooting

If you want to delete/remove the containers/machines, see the `Teardown` section above.

You can look at the logs of a container
```
# You can use the container anme
docker logs some-nginx
# Or use the container ID
docker logs 19d1cdda14a6
```

You can essentially SSH into the container by using the following command (use your own container ID, `docker ps --all`)
```
docker exec -it 19d1cdda14a6 bash
```

以上是关于markdown #Docker容器,基本nginx服务器暴露端口 - Window Guide.md的主要内容,如果未能解决你的问题,请参考以下文章

markdown [Docker HowtTo]如何创建Docker容器#docker #howto

Docker容器之内网独立IP访问

markdown PHPStorm远程调试Docker容器

markdown Docker容器中的BackstopJS

markdown Docker清除图像和容器

markdown [export container]如何将docker容器导出到其他机器。 #docker