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 configure priorities for Spark and OpenMPI to coexist on a cluster?
  • Run a Docker image as a command line utility in Windows?
  • Docker forever in “Docker is starting..” at windows task
  • Docker: MySQL-Socket created with wrong permissions when bind-mounted from host to container
  • Docker container file permission changing Automatically
  • persist mtu settings on boot2docker / docker-machine
  • 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.

  • Gitlab CI runner configuration with cache on docker
  • Docker with `/bin/bash -c` running mysql deamon
  • I am running 2 images with Docker Compose and I am having trouble hitting the localhost from my Mac. I am exposing ports 3000. Am I missing something?
  • change docker containers IP address
  • Error connecting to python server running in boot2docker (centos container | Windows 7.1 host)
  • Trying to pull image from private-repo.microsoft.com
  • 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.