1. Docker 安装 Nginx

#1. 搜索镜像 search 建议大家去docker搜索,可以看到帮助文档
#2. 拉取镜像 pull
#3、运行测试
# -d 后台运行
# --name 给容器命名
# -p 宿主机端口:容器内部端口

[root@qichao home]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
07aded7c29c6: Already exists
bbe0b7acc89c: Pull complete
44ac32b0bba8: Pull complete
91d6e3e593db: Pull complete
8700267f2376: Pull complete
4ce73aa6e9b0: Pull complete
Digest: sha256:06e4235e95299b1d6d595c5ef4c41a9b12641f6683136c18394b858967cd1506
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@qichao home]# docker run -d --name nginx01 -p 8090:80 nginx
6a5af82afd35ee550e3b6fcb826ceab5b8bde047be2ddb8e12f9a5f2d43b7b89
[root@qichao home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a5af82afd35 nginx "/docker-entrypoint.…" 10 seconds ago Up 9 seconds 0.0.0.0:8090->80/tcp, :::8090->80/tcp nginx01
[root@qichao home]# curl localhost:8090
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
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>
# 进入容器
[root@qichao /]# docker exec -it nginx01 /bin/bash
root@6a5af82afd35:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@6a5af82afd35:/# cd /etc/nginx
root@6a5af82afd35:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
root@6a5af82afd35:/etc/nginx#


Docker安装Nginx,Tomcat_docker

访问外网地址

Docker安装Nginx,Tomcat_d3_02

思考问题:我们每次改动nginx配置文件,都需要进入容器内部?十分的麻烦,要是可以在容器外部提供一个映射路径,达到在容器修改文件名,容器内部就可以自动修改?√数据卷!

2. Docker 安装 Tomcat

[root@qichao ~]# docker run -d -p 8080:8080 --name tomcat01 tomcat:9.0
414ac1a5ca17788fc4f7f4227bd3c311ed9f9ca8e87a5d8b541c319c86f98292
[root@qichao ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
414ac1a5ca17 tomcat:9.0 "catalina.sh run" 7 seconds ago Up 6 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp tomcat01
6a5af82afd35 nginx "/docker-entrypoint.…" 51 minutes ago Up 51 minutes 0.0.0.0:8090->80/tcp, :::8090->80/tcp nginx01
#测试访问有没有问题
[root@qichao ~]# curl localhost:8080

#进入容器
[root@qichao ~]# docker exec -it tomcat01 /bin/bash

# 发现问题:1、linux命令少了。 2.没有webapps


思考问题:我们以后要部署项目,如果每次都要进入容器是不是十分麻烦?要是可以在容器外部提供一个映射路径,webapps,我们在外部放置项目,就自动同步内部就好了!