【发布时间】:2020-01-20 00:11:17
【问题描述】:
我目前正在为一个项目学习 Docker,并在我打算更改的 PHP 网站上开始配置。问题是即使我在 Dockerfile 中设置了不同的版本,我也得到了相同的 PHP 版本。
这是我执行 docker-compose up 命令时的输出。 它继续使用 PHP 版本 7.0.33。这也是它在浏览器中显示的版本。
这是我的 docker-compose.yml 文件:
# tell docker what version of the docker-compose.yml were using
version: '3'
# define the network
networks:
web-network:
# start the services section
services:
# define the name of our service
# corresponds to the "--name" parameter
docker-php-cli:
# define the directory where the build should happened,
# i.e. where the Dockerfile of the service is located
# all paths are relative to the location of docker-compose.yml
build:
context: ./php-apache
# reserve a tty - otherwise the container shuts down immediately
# corresponds to the "-i" flag
tty: true
# mount the app directory of the host to /var/www in the container
# corresponds to the "-v" option
volumes:
- ./app:/var/www
# connect to the network
# corresponds to the "--network" option
networks:
- web-network
docker-nginx:
build:
context: ./nginx
# defines the port mapping
# corresponds to the "-p" flag
ports:
- "8080:80"
tty: true
volumes:
- ./app:/var/www
- ./nginx/conf.d:/etc/nginx/conf.d
networks:
- web-network
docker-php-fpm:
build:
context: ./php-fpm
tty: true
volumes:
- ./app:/var/www
networks:
- web-network
这些是 Docker 文件: php-apache 文件夹
FROM php:5.6-apache
RUN pecl install xdebug-2.6.0 \
&& docker-php-ext-enable xdebug
php-fpm 文件夹
FROM php:5.6-fpm
RUN pecl install xdebug-2.6.0 \
&& docker-php-ext-enable xdebug
我想为 PHP 5.6 更改它,但我不能,然后我测试了许多其他版本,它没有工作。
我确实尝试从每个 Dockerfile 中删除 RUN 部分。
有人可以帮我吗?
谢谢!
【问题讨论】:
-
您在
up之前做过docker-compose build吗? -
您可以在 up 命令中强制构建:
docker-compose up --build
标签: php docker docker-compose dockerfile