我需要在我的项目中遇到实例供应商的问题。
我的php dockerfile
FROM php:7.2.1-fpm
RUN apt-get update
# Install tools
RUN apt-get install -y \
python-setuptools \
software-properties-common \
wget \
git \
curl \
zip \
vim
RUN echo 'deb http://httpredir.debian.org/debian jessie contrib' >> /etc/apt/sources.list
RUN apt-get update
RUN export DEBIAN_FRONTEND=noninteractive && apt-get install -y --force-yes libssl-dev curl libcurl4-gnutls-dev libxml2-dev libicu-dev libmcrypt4 libmemcached11 openssl
#CONFIGURAÇÕES DO OPCACHE
RUN docker-php-ext-install opcache
#CONFIGURAÇÕES DO APCU
RUN pecl install apcu-5.1.5 && docker-php-ext-enable apcu
#LIBS EXTRAS
RUN docker-php-ext-install bcmath
RUN apt-get install -y libbz2-dev
RUN docker-php-ext-install bz2
RUN docker-php-ext-install mbstring
RUN apt-get install -y libpq-dev
RUN apt-get install -y libicu-dev
RUN docker-php-ext-install intl
#GD
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng16-16
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
#PDO
RUN docker-php-ext-install pdo_mysql
#sudo
RUN apt-get update && apt-get install -y sudo && rm -rf /var/lib/apt/lists/*
VOLUME /var/www/html
WORKDIR /var/www/html
RUN pwd
# Allow Composer to be run as root
ENV COMPOSER_ALLOW_SUPERUSER 1
# Install composer
RUN wget https://getcomposer.org/download/1.5.5/composer.phar
RUN chmod +x composer.phar
RUN sudo mv composer.phar /usr/local/bin/composer
# Install libs/var_dumper
RUN mkdir -p /var/.composer
RUN composer global --no-interaction --working-dir=/var/.composer require slim/slim
EXPOSE 9000
CMD ["php-fpm"]
我只是想将供应商文件夹移至var / www / html
Docker组成
nginx:
container_name: nginx
build: ./docker/nginx
ports:
- "80:80"
volumes:
- ./public:/var/www/html
links:
- php
- mysql
php:
container_name: php
build: ./docker/php7
volumes:
- ./public:/var/www/html
ports:
- "9000:9000"
links:
- mysql
mysql:
image: mysql:5.7
restart: always
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=testedb
供应商文件位于/var/.composer中,我无法访问它们。
我想知道如何正确构建图像以使用 slim 的框架,而其他图像则没有错误。
最佳答案
Docker文件
FROM php:7.2-fpm
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
RUN docker-php-ext-install mysqli
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy composer.lock and composer.json
COPY composer.json /var/www/html
# Copy existing application directory contents
COPY . /var/www/html
# Set working directory
WORKDIR /var/www/html
RUN composer install
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
Docker-compose.yml
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
volumes:
- ./:/var/www/html
- php-data:/var/www/html/vendor/
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www/html
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: testedb
MYSQL_ROOT_PASSWORD: root
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./docker/mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
php-data:
我这样做,创建3个卷并将供应商放入php-data
关于php - 带有Nginx,MySQL,php7和slimphp的Dockerfile,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57194754/