Home > Back-end >  Difference between running docker and docker compose
Difference between running docker and docker compose

Time:01-01

I am working with an docker image nanoninja/php-fpm:8.1. When I run the image manually, the PHP works.

docker container run --rm --name phpfpm -v $(pwd):/var/www/html -p 3000:3000 nanoninja/php-fpm php -S="0.0.0.0:3000" -t="/var/www/html"

enter image description here

But when I try to run the same image with docker-compose.yml file, I don't get a connection to PHP. Here is my very simple docker-compose.yml file:

version: '3'
services:
    php:
        image: nanoninja/php-fpm:8.1
        restart: always
        ports:
           - 3000:9000
        stdin_open: true
        tty: true

I'm not using a Dockerfile.

Question: How to run PHP without Nginx using only docker-compose.yml file?

Image link: https://github.com/nanoninja/php-fpm

CodePudding user response:

The docker-compose file equivalent to your docker container run command would be something like

version: "3"
services:
  php:
    image: nanoninja/php-fpm:8.1
    container_name: phpfpm
    restart: always
    ports:
      - 3000:3000
    command: php -S="0.0.0.0:3000" -t="/var/www/html"
    volumes:
      - ./:/var/www/html

The -v option becomes the volumes: section. The part after the image name becomes the command:. The -p option becomes the ports: section. --name becomes container_name:, etc.

  • Related