二、Docker部署步骤 1、项目编译成镜像 请cd到和Dockerfile同目录; 例如:cd /home/docker docker build -t website:latest . 2、查看镜像并创建容器 docker images #端口8081在website.conf中设定 #--privileged是给权限 不然进入容器systemctl命令没有权限 #-v /home/docker/upload:/var/www/website/admin/upload 路径需要根据项目目录而定 上传的附件映射到宿主主机 #-v /sys/fs/cgroup:/sys/fs/cgroup 解决权限问题 #/usr/sbin/init 解决权限问题 不能省略 docker run -it -p 8089:8081 --privileged --name web-site -v /home/docker/upload:/var/www/website/admin/upload -v /sys/fs/cgroup:/sys/fs/cgroup -d website:latest /usr/sbin/init 3、查看容器 docker ps -a 4、进入容器并启动服务 docker exec -it web-site /bin/bash /var/www/website/init.sh 5、查看容器运行日志 docker logs -f web-site 6、查看容器接口情况 curl http://127.0.0.1:8081/api/index.php/common/faqCate 7、查看宿主接口情况 curl http://127.0.0.1:8089/api/index.php/common/faqCate
项目语言PHP7.4、MariaDB/MySQL、Nginx、Redis
一、Dockerfile FROM centos:7 MAINTAINER 作者姓名 邮箱 可忽略 #设置容器时间和宿主主机一致 ENV TZ=Asia/Shanghai RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone #安装PHP7.4 RUN yum install epel-release -y RUN rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm RUN yum --enablerepo=remi-php74 install php -y RUN yum --enablerepo=remi-php74 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt php-cli php-common php-redis php-ldap php-mysql php-mysqli php-pdo php-fpm php-devel php-zip php-opcache -y RUN sed -i 's/^user\ =\ apache/user\ =\ nginx/' /etc/php-fpm.d/www.conf RUN sed -i 's/^group\ =\ apache/group\ =\ nginx/' /etc/php-fpm.d/www.conf RUN sed -i 's/^;listen\.owner\ =\ nobody/listen\.owner\ =\ nobody/' /etc/php-fpm.d/www.conf RUN sed -i 's/^;listen\.group\ =\ nobody/listen\.group\ =\ nobody/' /etc/php-fpm.d/www.conf RUN sed -i 's/^;listen\.mode\ =\ 0660/listen\.mode\ =\ 0660/' /etc/php-fpm.d/www.conf #安装Nginx RUN yum install nginx -y #复制项目Nginx配置 COPY ./website.conf /etc/nginx/conf.d/website.conf #复制项目 RUN mkdir -p /var/www/website COPY ./website/ /var/www/website COPY ./init.sh /var/www/website/init.sh RUN chmod -R 777 /var/www/website RUN ln -s /var/www/website/admin/upload /var/www/website/api/upload
标签:website,www,php,RUN,Linux,var,docker,PHP From: https://www.cnblogs.com/lovekingly/p/16998734.html