【问题标题】:Docker is always loading the wrong PHP version that I have setup in DockerfileDocker 总是加载我在 Dockerfile 中设置的错误 PHP 版本
【发布时间】: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


【解决方案1】:

您正在使用 docker-compose up 该命令的作用是,它从以前构建的图像中启动容器(查看您本地使用的图像 docker image ls)

更改 Dockerfile 后,您需要运行 docker-compose down 并再次使用 --build 标志。 docker-compose up --build

相关文档https://docs.docker.com/compose/reference/up/

【讨论】:

  • 谢谢,我注意到之前的评论。 =) 现在它正在工作,只需设置 mysql。
猜你喜欢
  • 2021-12-01
  • 2021-04-24
  • 1970-01-01
  • 2022-01-22
  • 2022-10-22
  • 2019-12-05
  • 1970-01-01
  • 2018-07-30
  • 1970-01-01
相关资源
最近更新 更多