简体   繁体   中英

Docker php version is incorrect with docker-compose.yml

I'am new in docker. I set php container with php version 7.2 but phpinfo() shows php version 7.0. What I'am doing wrong ?

My docker-compose.yml

version: '2'
services:
    mysql:
        image: mysql:5.7
        env_file:
            - ./mysql.env
        volumes:
            - ./storage/mysql:/var/lib/mysql
    web:
        image: nginx:latest
        build: ./fitter
        container_name: web
        ports:
            - 80:80
        volumes:
            - ./fitter:/var/www
            - ./nginx-site.conf:/etc/nginx/conf.d/site.conf
            - ./storage/app:/var/www/storage/app
            - ./storage/logs:/var/www/storage/logss
        links:
            - php
    php:
        image: php:7.2-fpm
        volumes:
            - ./fitter:/var/www

And nginx-site.conf

server {
    index index.php index.html;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass fitter_docker_php_1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Command like "docker exec web php -v" shows "PHP 7.0.15 (cli) (built: Jan 19 2017 21:25:43) ( NTS )"

down your Docker and remove images using

docker rmi $(docker image ls -aq)

then rebuild them

docker-compose up --build

there you go, new container building based on new images

When you run a set of services with docker-compose it will create a docker network and start all the services inside that network, that means that all your containers inside that network can communicate with each other and you can use the name you defined for each service as a DNS record.

Change this:

fastcgi_pass fitter_docker_php_1:9000;

To

fastcgi_pass php:9000;

Also if you changed the php image version you have to pull the new image before restarting your compose stack, as the container will need to be recreated with the new image.

And you can remove the "links" from your docker compose as its not necessary in this case and also a legacy feature, you can read more about that here: https://docs.docker.com/compose/compose-file/#links

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM