Docker容器化应用 :
*部署docker环境
注意事项:
建议使用Centos7-1810版本 在1511版本会出现驱动问题和iptables问题
1.先配置网络的yum文件:不会的可以参考这篇文档 https://blog.csdn.net/smileui/article/details/106738039
yum clean all; yum makecache
2.安装docker环境:
yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce docker-ce-cli containerd.io -y systemctl start docker systemctl enable docker
3…配置国内的仓库地址:实现快速部署镜像
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://2n9uoybw.mirror.aliyuncs.com"] } EOF
4.重现启动服务
systemctl daemon-reload && systemctl restart docker
准备部署wordpress需要的镜像文件
wordpress 基于 PHP+MySQL开发的一套博客系统,如果想运行需要使用LAMP或LNMP wordpress:latest 默认已经包含了AP或NP
mysql:5.7 安装MySQL数据库,建议使用5.6或5.7版本
[root@localhost ~]# docker pull wordpress:latest
[root@localhost ~]# docker pull mysql:5.7
一、 准备docker-compose工具
为接下来启动容器进行编排(类似日常生活中的工作计划)
LAMP 先启动mysql,再启动apache
部署wordpress应用时,应该先启动mysql容器,再启动wordpress
[root@localhost ~] REPOSITORY TAG IMAGE ID CREATED SIZE wordpress latest ee025cbcbc20 3 days ago 539MB mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB centos latest 0f3e07c0138f 2 months ago 220MB
二、准备epel YUM源
[root@localhost ~] 7.repo [root@localhost ~] CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo docker-ce.repo
准备pip工具,用于批量管理python语言开发的工具包(和GitHub二进制的区别主要在于版本)
[root@localhost ~]
由于有安装依赖,建议把下面所有软件包安装后,再安装docker-compose
[root@localhost ~]
三、更新pip版本
[root@localhost ~]
四、切换国内源
[root@localhost ~] [root@localhost ~] [root@localhost ~] [root@localhost ~] [root@localhost ~] [root@localhost ~]
五、安装docker-compose
[root@localhost ~]
六、验证是否安装成功
[root@localhost ~] docker-compose version 1.25.0, build b42d419 docker-py version: 4.1.0 CPython version: 2.7.5 OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017
七、准备容器镜像文件
[root@localhost ~] REPOSITORY TAG IMAGE ID CREATED SIZE wordpress latest ee025cbcbc20 3 days ago 539MB mysql 5.7 1e4405fe1ea9 2 weeks ago 437MB
八、创建目录文件
[root@localhost ~] [root@localhost ~]
九、编写docker-compose.yaml文件:
注意该文件的格式 严格注意空格
[root@localhost wordpressproject] ```powershell version: '3' services: db: image: mysql:5.7 volumes: - "./data:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress expose: - 3306 wordpress: depends_on: - db image: wordpress:latest links: - db ports: - "8080:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress
上边的代码很重要尤其是缩进问题一定处理好
十、开启ip转发功能(非常重要)
[root@localhost wordpressproject] [root@localhost wordpressproject] [root@localhost wordpressproject]
十一、立即生效 这部分是帮助的命令 下边才是具体的启动命令
docker-compose相关命令:
如何使用docker-compose
[root@localhost wordpressproject] [root@localhost wordpressproject]
此命令只能在工程目录中使用,用于启动工程
[root@localhost wordpressproject]
停止并删除工程已经创建的容器
十二、启动docker-compse:
[root@localhost wordpressproject] Creating network "wordpressproject_default" with the default driver Creating wordpressproject_db_1 ... done Creating wordpressproject_wordpress_1 ... done [root@localhost ~] CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4cf5f4cee330 wordpress:latest "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:8080->80/tcp wordpressproject_wordpress_1 4d9cb6aee451 mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp wordpressproject_db_1 [root@localhost ~] anaconda-ks.cfg mysql.tar wordpressproject wordpress.tar [root@localhost ~] [root@localhost wordpressproject] data docker-compose.yaml [root@localhost wordpressproject] auto.cnf client-key.pem ib_logfile1 private_key.pem sys ca-key.pem ib_buffer_pool ibtmp1 public_key.pem wordpress ca.pem ibdata1 mysql server-cert.pem client-cert.pem ib_logfile0 performance_schema server-key.pem [root@localhost wordpressproject] db.opt
十三、最后测试效果 省略了中途出现的配置用户名 数据库的截图 大同小异
原文链接:https://blog.csdn.net/smileui/article/details/108556877?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168623078216800185866810%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168623078216800185866810&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-15-108556877-null-null.268%5Ev1%5Ekoosearch&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