思路
1、搜索nginx镜像
docker search nginx
2、拉取镜像
docker pull nginx
3、启动镜像
docker run nginx
4、进入容器内部
docker exec -it 容器id /bin/bash
5、远程访问nginx
http://42.192.206.87:3344/

[root@VM-0-11-centos home]# docker seach nginx
[root@VM-0-11-centos home]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
b4d181a07f80: Pull complete
edb81c9bc1f5: Pull complete
b21fed559b9f: Pull complete
03e6a2452751: Pull complete
b82f7f888feb: Pull complete
5430e98eba64: Pull complete
Digest: sha256:47ae43cdfc7064d28800bc42e79a429540c7c80168e8c8952778c0d5af1c09db
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@VM-0-11-centos home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4f380adfc10f 2 days ago 133MB
centos latest 300e315adb2f 6 months ago 209MBd 后台运行
--name 给容器命名
-p 宿主机端口:容器端口
[root@VM-0-11-centos home]# doccker run -d --name nginx01 -p:3344:80 nginx
-bash: doccker: 未找到命令
[root@VM-0-11-centos home]# dccker run -d --name nginx01 -p:3344:80 nginx
-bash: dccker: 未找到命令
[root@VM-0-11-centos home]# docker run -d --name nginx01 -p:3344:80 nginx
85e958e7da931029c2aa3d0134e4d5488724498068ab438aba9a8741e060bfa6
[root@VM-0-11-centos home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4f380adfc10f 2 days ago 133MB
centos latest 300e315adb2f 6 months ago 209MB
[root@VM-0-11-centos home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85e958e7da93 nginx "/docker-entrypoint.…" 41 seconds ago Up 40 seconds 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx01
7f801f6d7bb4 centos "/bin/sh -c 'while t…" 51 minutes ago Up 51 minutes sweet_mendel
[root@VM-0-11-centos home]# curl localhost:3344
<!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>.
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>
[root@VM-0-11-centos home]# dcoker ps
-bash: dcoker: 未找到命令
[root@VM-0-11-centos home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85e958e7da93 nginx "/docker-entrypoint.…" 7 minutes ago Up 7 minutes 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx01
7f801f6d7bb4 centos "/bin/sh -c 'while t…" 58 minutes ago Up 58 minutes sweet_mendel
进入容器
[root@VM-0-11-centos home]# docker exec -it nginx01 /bin/bash
root@85e958e7da93:/# where nginx
bash: where: command not found
root@85e958e7da93:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@85e958e7da93:/# cd etc/nginx/
root@85e958e7da93:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
root@85e958e7da93:/etc/nginx# exit #退出容器
exit
[root@VM-0-11-centos home]# docker stop nginx
Error response from daemon: No such container: nginx
端口暴露的概念:

网友评论