docker 安装 nginx
[root@fengfang /]# docker search nginx --limit=2
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 13495 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1841 [OK]
[root@fengfang /]# docker pull nginx #下载nginx镜像
Using default tag: latest latest: Pulling from library/nginx latest: Pulling from library/nginx 6ec8c9369e08: Pull complete d3cb09a117e5: Pull complete 7ef2f1459687: Pull complete e4d1bf8c9482: Pull complete 795301d236d7: Pull complete Digest: sha256:504182836fe6ee6347a4a865dc685e70d006790deab072ea5fac9099a47ebdde Status: Downloaded newer image for nginx:latest docker.io/library/nginx:latest [root@fengfang /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 8cf1bfb43ff5 28 minutes ago 132MB centos latest 831691599b88 5 weeks ago 215MB [root@fengfang /]# docker run -d --name nginx01 -p 7676:80 nginx #启动运行镜像 -d后台运行 -p暴露端口(容器内端口:宿主机端口) --name 重命名 10aad085e617ba2382d625b77b63a1c4f911d7b38f750af70e8d3cf02c2c3872 [root@fengfang /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 10aad085e617 nginx "/docker-entrypoint.…" 3 seconds ago Up 2 seconds 0.0.0.0:7676->80/tcp nginx01 [root@fengfang /]# curl localhost:7676 #测试运行容器是否有问题? <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { 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>
安装tomcat
官方是使用直接运行的,使用以下命令,我们使用一般是先下载再运行
命令:docker run -it --rm tomcat9.0
我们之前的启动都是后台,停止了容器之后,容器还是可以找到,docker run -it --rm 容器名 这种命令一般表示用来测试,用完就删除
[root@fengfang /]# docker search tomcat limit 3 "docker search" requires exactly 1 argument. See 'docker search --help'. Usage: docker search [OPTIONS] TERM Search the Docker Hub for images [root@fengfang /]# docker search tomcat --limit=3 #查找tomcat镜像 NAME DESCRIPTION STARS OFFICIAL AUTOMATED tomcat Apache Tomcat is an open source implementati… 2785 [OK] bitnami/tomcat Bitnami Tomcat Docker Image 35 [OK] jelastic/tomcat An image of the Tomcat Java application serv… 2 [root@fengfang /]# docker pull tomcat #下载tomcat最新版本镜像 Using default tag: latest latest: Pulling from library/tomcat e9afc4f90ab0: Pull complete 989e6b19a265: Pull complete af14b6c2f878: Pull complete 5573c4b30949: Pull complete fb1a405f128d: Pull complete 612a9f566fdc: Pull complete 4226f9b63dac: Pull complete cb8bfe875d7f: Pull complete 5aa366608b6d: Pull complete 4b7c9018ca5f: Pull complete Digest: sha256:46456ccf216f2fde198844d5c7d511f60e3ffc2ea3828e0cce9a2eed566e48e2 Status: Downloaded newer image for tomcat:latest docker.io/library/tomcat:latest [root@fengfang /]# docker run -d -p 5566:8080 --name tomcat01 tomcat #启动tomcat容器 8c73c081a66122d2ad9ffe4a2f692dbbb482c032f16dfffc0a4a47275601e1e6 [root@fengfang /]# docker exec -it tomcat01 /bin/bash root@8c73c081a661:/usr/local/tomcat# ll bash: ll: command not found root@8c73c081a661:/usr/local/tomcat# ls BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work root@8c73c081a661:/usr/local/tomcat# cd webapps root@8c73c081a661:/usr/local/tomcat/webapps# ls root@8c73c081a661:/usr/local/tomcat/webapps#
root@8c73c081a661:/usr/local/tomcat# cp -r webapps.dist/* webapps #将文件夹 webapps.dist所有内容拷贝到webapps文件夹下
安装 tomcat后,发现linux命令少了,且webapps文件夹下没有内容,是因为阿里云的原因,默认是最小的镜像,所有不必要的都剔除掉,保证最小可运行环境
思考问题:我们以后要部署项目,每次都要进入容器,非常麻烦,我要是可以在容器外部提供一个映射路径,webapps,我们在外部放置项目,就自动同步到内部就好了
部署ES+kibana
以下为部署elasticsearch的官方命令
$ docker network create somenetwork $ docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:tag
启动之后发现问题:
1、暴露的端口很多
2、十分的消耗内存
3、ES的数据一般需要放置到安全目录,即挂载
4、--net somenetwork 网络配置
故需给环境配置设置 ,需使用下面的命令:
docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.8.0
测试elasticasearch 是否成功:
[root@fengfang /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3eec0bf1ea48 elasticsearch:7.8.0 "/tini -- /usr/local…" About a minute ago Up About a minute 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch [root@fengfang /]# curl localhost:9200 { "name" : "3eec0bf1ea48", "cluster_name" : "docker-cluster", "cluster_uuid" : "GYqf5vHnRRWb_jzblGF7FQ", "version" : { "number" : "7.8.0", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65", "build_date" : "2020-06-14T19:35:50.234439Z", "build_snapshot" : false, "lucene_version" : "8.5.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } [root@fengfang /]#
docker stats #查看容器使用资源的情况
可视化
portainer(先用这个)
如果仅有一个docker宿主机,则可使用单机版运行,运行以下命令就可以启动了:
docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --name prtainer-test portainer/portainer
首次登陆需要注册用户,给admin用户设置密码:
单机版这里选择local即可
点击“Connect”之后就是下面的界面
3.2、集群运行
在有多台Docker的情况下,进行集群管理就十分重要了,Portainer也支持集群管理,Portainer可以和Swarm一起来进行集群管理操作,Swarm搭建参考上文。
通过以下命令启动
docker run -d -p 9000:9000 --restart=always --name prtainer-test portainer/portainer
选择Remote
输入swarm01的ip,然后点击Connect。登录成功之后如下
可以在Endpoints中新增Docker节点
新增之后,如下
然后通过如下方式进行切换节点
双击
就可以切换节点,进行管理。