Some questions about docker compose

Hello,
I am a newbie and have some questions about the docker compose:

1- In an internet article, a file called docker-compose.yaml was created to build the container. Can I create a YAML file for each container and use docker compose up -d to run it? If this is possible, how can I specify the input file?

2- I want to start a website that uses Nginx web server and PHP and JavaScript programming languages. Do I need a container for each (Nginx, PHP and JavaScript)?

3- The following configuration file creates a container using image and connects the containers using links:

version: '3.9'
services:
  web:
    image: nginx:latest
    ports:
      - '80:80'
    volumes:
      - ./src:/var/www/html/index.html
    links:
      - php-fpm
  php-fpm:
    image: php:8-fpm

Is it right?

4- I have created a container and now I want to make some changes in the YAML file and apply these new changes to the container. What should I do?

5- Is there a special folder for making containers? For example, the /var/www directory is for the web server.

I would be grateful if you could answer my questions clearly and based on the numbers.

Cheers.

Hi

1- No, in your example, for every website you have, you would create a docker-compose file.

2- Depends, normally when working with containers, you should have 1 container pr application, meaning: 1 container for database, 1 container for webserver, 1 container for proxy and so on, javascript is client side so that isnt needed.

3- That starts an nginx and a php-fpm server, then its your job to configure nginx to USE the php-fpm via ngnix configuration files, to make it simple, you can use the build in php-apache image:

version: '3'
services:
  php:
    ports:
      - '80:80'
    container_name: my-apache-php-app
    volumes:
      - './src:/var/www/html'
    image: 'php:apache'

4- you run docker compose up -d again

5- Every image has a default location, fx. the php:apache image i gave you an example on earlier, the web server is expected to see web files here: /var/www/html.
For each image you use, its normal that these kind of infomation is documented on hub, fx: Docker

1 Like

Hi,
Thank you so much for your reply.
1- So, in the new version of docker compose, the -f parameter has been removed. I had seen examples like docker-compose -f docker-compose.prod.yml up -d on the internet. When I want to create a new container, should I delete the docker-compose.yaml file and create it with the new container settings?

2- If the JavaScript is server-side, then I have to create another container for it.

3- Why did you use version: '3'? Can this number be anything?

4- Does the following configuration file connect Nginx to PHP-FPM?

version: '3.9'

services:
  web:
    image: nginx:latest
    ports:
      - '80:80'
    volumes:
      - ./src:/var/www/html/index.html
    links:
      - php-fpm
  php-fpm:
    image: php:8-fpm
    volumes:
      - ./src:/var/www/html

Cheers.

1- im pretty sure -f still exists, and no, you should not delete your compose file, the compose file is your recipe for your application, instead you should have different folders for each project

2- if you by javascript server side, mean nodejs or similar, then yes, there should be a container for it.

3- the number 3 is the version of the compose file, i just used 3 for none specific reason, you can check the difference here: Compose file versions and upgrading | Docker Docs

4- it puts them in the same network yes, but you have to configure nginx, in nginx configuration to use “php-fpm”

1 Like