How to mount volume in docker compose version '2' format

So I have a trouble with mount new format version 2 docker compose file.
I have the code in folder wordpress inside where is location docker-compose file also I have inside the folder code docker file like this:

FROM debian:jessie
VOLUME /var/www/wordpress

When I used old format like this:

  • How to name Dockerfiles
  • How to configure dns for concourse build container?
  • Docker + nginx + PHP - nginx does not point to the root directory?
  • disable firewalld/iptables in centos7 minimal version
  • Download key with `gpg --recv-key` and simultaneously check fingerprint in a script
  • How to use env attribute of Vagrant Docker provider?
  • application:
        build: code
        volumes:
            - ./wordpress:/var/www/wordpress
            - ./logs/wordpress:/var/www/wordpress/app/logs
        tty: true
    db:
        image: mysql
        ports:
            - 3306:3306
        environment:
            MYSQL_ROOT_PASSWORD: root
            MYSQL_DATABASE: somename
            MYSQL_USER: root
            MYSQL_PASSWORD: root
    php:
        build: php-fpm
        ports:
            - 9001:9001
        volumes_from:
            - application
        links:
            - db
    nginx:
        build: nginx
        ports:
            - 8080:80
        links:
            - php
        volumes_from:
            - application
        volumes:
            - ./logs/nginx/:/var/log/nginx
    elk:
        image: willdurand/elk
        ports:
            - 81:80
        volumes:
            - ./elk/logstash:/etc/logstash
            - ./elk/logstash/patterns:/opt/logstash/patterns
        volumes_from:
            - application
            - php
            - nginx
    

    When I started use version ‘2’ the same as code as previous version I got any error so I reformat my compose file and move dockerfile from code folder to insider main folder where is location docker-compose file. My new version docker-compose became looks like as:

    version: '2'
    services:
      web:
        build: .
        volumes:
         - /wordpress:/var/www/wordpress
         - /logs/wordpress:/var/www/wordpress/app/logs
        tty: true
    
      db:
          image: mysql
          ports:
              - 3306:3306
          environment:
              MYSQL_ROOT_PASSWORD: root
              MYSQL_DATABASE: somename
              MYSQL_USER: root
              MYSQL_PASSWORD: root
      php:
          build: php-fpm
          ports:
              - 9001:9001
          volumes_from:
              - web
          links:
              - db
      nginx:
          build: nginx
          ports:
              - 82:82
          links:
              - php
          volumes_from:
              - web
          volumes:
              - /logs/nginx/:/var/log/nginx
      elk:
          image: willdurand/elk
          ports:
              - 81:80
          volumes:
              - /elk/logstash:/etc/logstash
              - /elk/logstash/patterns:/opt/logstash/patterns
          volumes_from:
              - web
              - php
              - nginx
    

    Finally after reformat the code docker-compose was successfully build and up but when I open my php and nginx container inside both of them in /var/www/worpdress I have just empty folder app is not my wordpress project.
    In which place I was mistake with settings mount project volume?
    Thanks in advance.

  • Copying a directory into a docker image while skipping given sub directories
  • phpMyAdmin inside docker container via nginx reverse proxy
  • docker-compose volumes with a custom docker file
  • Jenkins and Docker
  • Building docker for the ARM-64 architecture
  • Docker private repo with multiple images
  • One Solution collect form web for “How to mount volume in docker compose version '2' format”

    The problem is with the way you are defining the local directories to be used for the volumes. In your previous version, you were using ./wordpress, while in the new one, you’re using just /wordpress.

    When referencing local directories for volume mappings, they always have to start with ./ – please try this:

    version: '2'
    services:
      web:
        build: .
        volumes:
          - ./wordpress:/var/www/wordpress
          - ./logs/wordpress:/var/www/wordpress/app/logs
    

    One more thing: I recommend to always enclose the volume mappings in double quotes to avoid issues with space characters, e.g.:

    version: '2'
    services:
      web:
        build: .
        volumes:
          - "./wordpress:/var/www/wordpress"
          - "./logs/wordpress:/var/www/wordpress/app/logs"
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.