- Start container in background: run -d (for running in background) with port mapping
# Pull nginx
isaac@isaac-KVM:~$ docker pull nginx:latest
latest: Pulling from library/nginx
fc7181108d40: Pull complete
c4277fc40ec2: Pull complete
780053e98559: Pull complete
Digest: sha256:bdbf36b7f1f77ffe7bd2a32e59235dff6ecf131e3b6b5b96061c652f30685f3a
Status: Downloaded newer image for nginx:latest
isaac@isaac-KVM:~$
isaac@isaac-KVM:~$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 719cd2e3ed04 4 days ago 109MB
ubuntu latest 7698f282e524 4 weeks ago 69.9MB
# Start nginx, specify port mapping from 1234 to 80 in container
isaac@isaac-KVM:~$ docker container run -d --name webwww -p 0.0.0.0:1234:80 nginx
c1b65461eefde6a3e86509602982e2eeaf7616838efa369d5504b2c9c412f8db
# List container, confirmed port mapping
isaac@isaac-KVM:~$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c1b65461eefd nginx "nginx -g 'daemon of…" 9 hours ago Up 9 hours 0.0.0.0:1234->80/tcp webwww
# Test 80 port is unreachable
isaac@isaac-KVM:~$ curl http://10.206.84.167:80
curl: (7) Failed to connect to 10.206.84.167 port 80: Connection refused
# Test 1234 port is available
isaac@isaac-KVM:~$ curl http://10.206.84.167:1234
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
沒有留言:
張貼留言