dockerfile文件:
FROM php:7.4-apache
LABEL name="bianca.lk.alex@outlook.com"
RUN apt-get update && \
apt-get install -y curl \
git \
zip \
wget \
vim &&\
docker-php-ext-install pdo pdo_mysql bcmath
RUN curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/5.3.3.tar.gz && \
tar xfz /tmp/redis.tar.gz && \
rm -r /tmp/redis.tar.gz && \
mkdir -p /usr/src/php/ext && \
mv phpredis-5.3.3 /usr/src/php/ext/redis && \
docker-php-ext-install redis
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer \
&& composer config -g repo.packagist composer https://mirrors.aliyun.com/composer
RUN chown -R www-data:www-data /var/www/html && a2enmod rewrite
构建镜像:
docker build -t php-apache .
自定义网络:
docker network create --subnet 172.20.0.0/24 --gateway 172.20.0.1 mynet
mysql,redis
# mysql
docker run -itd -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name mysql --net mynet -v /var/mysql/data/:/var/lib/mysql mysql:5.7
# redis
docker run -p 6379:6379 -d --name redis --net mynet redis redis-server
# node
docker run -itd --name node -v /var/html/:/html --net mynet node
php-apache 与 laravel
启动 php-apache 容器
docker run -d -p 80:80 --name php-apache -v /var/html/:/var/www/html --net mynet php-apache
下载 laravel
docker exec -it php-apache /bin/bash
root@07b61ff870a4:/var/www/html# composer create-project laravel/laravel --prefer-dist blog .
权限问题
chown -R www-data:www-data /var/www/html/blog/storage/
chown -R www-data:www-data /var/www/html/blog/bootstrap/