Docker三剑客之docker-compose+wordpress的博客搭建

Docker三剑客之docker-compose

docker容器的编排工具:

解决相互有依赖关系的多个容器的管理

//验证已有docker-compose命令

[root@localhost ~]# docker-compose -v docker-compose version 1.25.0, build 0a186604

docker-compose的配置文件实例

通过识别一个docker-compose.yml的配置文件,去管理容器

//设置tab键的空格数量

[root@localhost ~]# vim .vimrc set tabstop=2 [root@localhost ~]# source .vimrc
[root@localhost ~]# mkdir compose_test [root@localhost ~]# cd compose_test/ [root@localhost compose_test]# vim docker-compose.yml version: "3" services: nginx: container_name: web-nginx image: nginx restart: always ports: - 90:80 volumes: - ./webserver:/usr/share/nginx/html

第一个部分:version:指定格式的版本

第二部分:services:定义服务,(想要运行什么样的容器)

//运行docker-compose规定的容器:

PS:在执行这条命令的当前目录下,也需要有一个docker-compose.yml的配置文件,并且通常只有一个

[root@localhost compose_test]# docker-compose up -d [root@localhost compose_test]# cd webserver/ [root@localhost webserver]# echo 123456 > index.html [root@localhost webserver]# curl 127.0.0.1:90 123456

//停止运行

[root@localhost compose_test]# docker-compose stop

//重启

[root@localhost compose_test]# docker-compose restart

//如果在当前目录没有docker-compose.yml这个文件,可以通过-f来指定docker-compose.yml文件位置

[root@localhost ~]# docker-compose -f compose_test/docker-compose.yml start

并且,在运行container的过程中,还可以支持Dockerfile

[root@localhost compose_test]# vim Dockerfile [root@localhost compose_test]# cat Dockerfile FROM nginx ADD webserver /usr/share/nginx/htm [root@localhost compose_test]# vim docker-compose.yml version: "3" services: nginx: build: . container_name: web-nginx image: new-nginx:v1.0 restart: always ports: - 90:80 [root@localhost compose_test]# docker-compose stop [root@localhost compose_test]# docker-compose rm [root@localhost compose_test]# docker-compose up -d [root@localhost compose_test]# curl 127.0.0.1:90 123456 [root@localhost compose_test]# cd webserver/ [root@localhost webserver]# echo 654321 > index.html [root@localhost webserver]# curl 127.0.0.1:90 123456

搭建wordpress的博客

[root@localhost ~]# mkdir wordpress [root@localhost ~]# docker load < wordpress.tar [root@localhost ~]# cd wordpress/ [root@localhost wordpress]# vim docker-compose.yml version: "3.1" services: wordpress: image: wordpress restart: always ports: - 8080:80 environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: 123.com WORDPRESS_DB_NAME: wordpress db: image: mysql:5.7 restart: always environment: MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: 123.com MYSQL_ROOT_PASSWORD: 123.com [root@localhost wordpress]# docker-compose up -d

//浏览器访问本机的8080端口:(192.168.1.70:8080)

Docker三剑客之docker-compose+wordpress的博客搭建插图

Docker三剑客之docker-compose+wordpress的博客搭建插图1

Docker三剑客之docker-compose+wordpress的博客搭建插图2

Docker三剑客之docker-compose+wordpress的博客搭建插图3

原文链接:https://blog.csdn.net/weixin_45636702/article/details/104015622?ops_request_misc=&request_id=d03d454821fa40db84ee36359e962fbd&biz_id=&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~koosearch~default-27-104015622-null-null.268%5Ev1%5Econtrol&utm_term=docker%E3%80%81wordpress%E3%80%81wordpress%E5%BB%BA%E7%AB%99%E3%80%81wordpress%E4%B8%BB%E9%A2%98%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享