Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: In file './docker-compose.yml', service 'networks' must be a mapping not an array. #9413

Closed
Aqrus404 opened this issue Apr 23, 2022 · 7 comments

Comments

@Aqrus404
Copy link

Aqrus404 commented Apr 23, 2022

It seems like I've tried every spacing combination there is, but it still doesn't work. Do you guys have any ideas?

version: '2'

services:
  proxy:
    build: ./
  networks:
    - example1
    - example2
  ports:
    - "80:80"
    - "443:443"

networks:
  example1:
    external:
      - name: example1_default
  example2:
    external:
      - name: example2_default

@glours
Copy link
Contributor

glours commented Apr 23, 2022

In your example the networks property of your proxy service isn't correctly indented so Compose identified it as a new service called networks

try this instead (FYI you don't need the version property anymore)

services:
  proxy:
    build: ./
    networks:
      - example1
      - example2
    ports:
      - "80:80"
      - "443:443"

networks:
  example1:
    external:
      - name: example1_default
  example2:
    external:
      - name: example2_default

@kaffarell
Copy link

kaffarell commented Apr 23, 2022

The problem is that you cannot put a "-" in front of the name attribute.

version: '3.8'

services:
  proxy:
    build: ./
    networks:
      - example1
      - example2
    ports:
      - "80:80"
      - "443:443"

networks:
  example1:
    external:
      name: example1_default
  example2:
    external:
      name: example2_default

Docker compose docs: https://docs.docker.com/compose/networking/

As external.name is deprecated (or soon to be deprecated) you should use this syntax:

version: '3.8'

services:
  proxy:
    build: ./
    networks:
      - example1
      - example2
    ports:
      - "80:80"
      - "443:443"

networks:
  example1:
    name: example1_default
    external: true
  example2:
    name: example2_default
    external: true

Found here: docker-archive/compose-cli#1856

@Aqrus404
Copy link
Author

Oh my god you guys are amazing! I wasn't even able to respond to @kaffarell and you solved it! thank you a lot!

@glours glours closed this as completed Apr 23, 2022
@Noelleganyou
Copy link

Lorsque je lance mon fichier docker-compose.yml, cela me met "service must be a mapping" ou "volume must be a mapping"

version: '3'
services:
db:
wordpress:
depends_on:

  • db
    image: mysql:5.7
    wordpress:latest
    ports:
  • "8000:80"
    volumes:
  • db_data:/var/lib/mysql
    db_data: {}
    restart: always
    MYSQL_ROOT_PASSWORD: wordpress
    MYSQL_DATABASE: wordpress
    MYSQL_USER: wordpress
    MYSQL_PASSWORD: wordpress
    environment:
    WORDPRESS_DB_HOST: db:3306
    WORDPRESS_DB_USER: wordpress
    WORDPRESS_DB_PASSWORD: wordpress
    WORDPRESS_DB_NAME: wordpress

@glours
Copy link
Contributor

glours commented Nov 30, 2022

@Noelleganyou le fichier docker-compose.yml doit être au format Yaml qui accorde une importance particulière aux identations pour définier des blocs de données
Vous pouvez vous inspirez de l'exemple avec wordpress et mysql proposé dans awesome-compose

@Noelleganyou
Copy link

@glours Merci beaucoup

@Noelleganyou
Copy link

Noelleganyou commented Dec 13, 2022

Bonsoir, SVP j'ai un problème avec mon code java. J'ai écrit un code sur eclipse permettant de calculer le quotient d'une division et cela doit vérifier si le diviseur et le dividende entrés sont positif ou négatif.
Voici le programme :

public class Principale03 {

public static void main(String[] args) {
	// Déclaration des variables
	int diviseur;
	double dividende, quotient;
	
	//Enregistrement des valeurs entrées par l'utilisateur
	Scanner clavier = new Scanner(System.in);
	System.out.print("Entrer la valeur du dividende :");
	dividende = clavier.nextDouble();
	System.out.print("Entrer la valeur du diviseur :");
	diviseur = clavier.nextInt();
	
	//calcul du quotient
	quotient = dividende / diviseur;
	System.out.print("Le quotient est : " + quotient);
	clavier.close();

}

public static void vérification(int diviseur, double dividende, double quotient) throws Exception {
		if ((dividende > 0) && (diviseur > 0)) throw new Exception("Le quotient est : " + quotient);
		if ((dividende < 0) | (diviseur < 0)) throw new Exception("Veuiller entrer un nombre positif");
		
		
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants