一.什么是dockerfile
Dockerfile 是一个文本文件,其中包含了构建 Docker 镜像的指令。它描述了镜像的构建过程,包括基础镜像、安装的软件、配置信息等。
Dockerfile 以指令的形式定义了构建镜像的步骤,每一行指令都是一个独立的步骤。这些指令可以包括从官方仓库获取基础镜像、运行命令、添加文件、设置环境变量等。
二.什么是docker compose
docker compose是 Docker 公司提供的一种用于定义和运行多容器应用的工具。它允许用户通过一个简单的 YAML 文件来描述应用的各个服务,并一次性启动或停止整个应用。
三.编写dockerfile
制作nginx的镜像:
#指定基础镜像
FROM daocloud.io/library/centos:7
#指定作者
LABEL maintainer="kingshot" build-time="2024-01-01" project="wordprees"
#RUN用来执行shell命令
RUN yum -y install epel-release
RUN yum -y install nginx
#copy用来将宿主机的内容拷贝到镜像
#ADD等同于COPY,但是不同在于ADD可以拷贝网络资源;ADD可以在拷贝压缩包是,可以将解压缩的内容拷贝到镜像中
COPY ./nginx.conf /etc/nginx/nginx.conf
#指定服务端口
EXPOSE 8080
#指定卷
VOLUME ["/usr/share/nginx/html"]
#ENV设置环境变量
ENV nginx_level=1.16.1
#夯住
CMD ["nginx","-g","daemon off;"]
四.制作wordpress镜像
[root@host1 ~]# mkdir /root/wordpress
[root@host1 ~]# cd wordpress/
[root@host1 wordpress]# vim Dockerfile
[root@host1 wordpress]# mv /root/wordpress-5.9.1-zh_CN.tar.gz /root/wordpress
[root@host1 wordpress]#mv /etc/nginx.conf /root/wordpress/nginx.conf
FROM daocloud.io/library/centos:7
LABEL maintainer="kingshot" build-time="2024-01-01" project="wordpress"
RUN yum -y install epel-release
RUN yum -y install nginx
RUN yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
RUN yum install -y php80-php-xsl php80-php php80-php-cli php80-php-devel php80-php-gd php80-php-pdo php80-php-mysql php80-php-fpm
ADD wordpress-5.9.1-zh_CN.tar.gz /usr/share/nginx/
COPY ./nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
COPY start.sh /
ENTRYPOINT ["sh","/start.sh"]
制作启动脚本:
[root@host1 wordpress]# vim start.sh
chmod 777 /usr/share/nginx/wordpress -R nginx && /opt/remi/php80/root/usr/sbin/php-fpm if [ $? -eq 0 ];then echo "nginx和php启动成功" else echo "启动失败" fi tailf /var/log/nginx/*
nginx配置文件:
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. server { listen 80; server_name root; location / { root /usr/share/nginx/wordpress; index index.php; } location ~ \.php$ { root /usr/share/nginx/wordpress; #指定网站目录 fastcgi_pass 127.0.0.1:9000; #指定访问地址 fastcgi_index index.php; #指定默认文件 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #站点根目录,取决于root配置项 include fastcgi_params; #包含nginx常量定义 } } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2; # listen [::]:443 ssl http2; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # } }
五.制作镜像并启动wordpress
[root@host1 wordpress]# docker build -t mywordpress:v1.0 .
[root@host1 wordpress]# docker run -itd -p 80:80 mywordpress:v1.0
六. 拉取并运行mysql5.7镜像
[root@host1 wordpress]# docker pull daocloud.io/library/mysql:5.7
[root@host1 wordpress]# docker run -itd -e MYSQL_ROOT_PASSWORD=123 -e MYSQL_DATABASE=wordpress daocloud.io/library/mysql:5.7
[root@host1 wordpress]# docker run -itd -p 80:80 mywordpress:v1.0
七.制作docker compose
[root@host1 wordpress]# vim Docker compose.yaml文章来源:https://www.toymoban.com/news/detail-834599.html
version: '3' services: wordpress: build: . container_name: wordpress-web ports: - "80:80/tcp" - "443:443/tcp" links: - database:wordpress.db.com depends_on: - database database: image: daocloud.io/library/mysql:5.7 container_name: wordpress-db environment: - MYSQL_ROOT_PASSWORD=123456 - MYSQL_DATABASE=wordpress #选择挂载路径 volumes: - /root/wordpress/data:/var/lib/mysql
八.启动
[root@host1 wordpress]# docker compose up
###docker compose up -d:后台启动文章来源地址https://www.toymoban.com/news/detail-834599.html
到了这里,关于使用dockerfile以及docker compose部署搭建wordpress平台的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!