Raiden616
Raiden616

Reputation: 1564

Cannot mount volume with docker-compose

I am trying to run up a docker container with a mounted local volume using docker-compose. In failure to get it working, I have reduced by docker-compose down to the most basic version:

version: '2'

services:
  php:
    image: php:5.6-apache
    ports:
      - "8080:80"
    volumes:
      - .:/var/www/html

Upon doing this the mount appears in docker inspect:

"Mounts": [
            {
                "Type": "bind",
                "Source": "/home/clark/Projects/apis/contracts",
                "Destination": "/var/www/html",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""
            }
        ],

But /var/www/html directory on the container is empty.

I have tried every combination I can think of. Absolute paths, relative paths, ${pwd}, named volumes, mounting to a directory that exists, mounting to a directory that doesn't exist... It's driving me crazy.

PLEASE can someone tell me what I'm doing wrong???

Upvotes: 5

Views: 6303

Answers (1)

papey
papey

Reputation: 4144

Works here, the only difference is a version 3 docker-compose file.

mkdir /tmp/compose-test && cd /tmp/compose-test
touch iam_a_file

Docker compose file :

---
version: '3'

services:
  test:
    image: busybox
    command: ls -la /var/www/html
    volumes:
      - .:/var/www/html

Ensure config is ok :

docker-compose config

Up all the stuff

docker-compose up
Creating composetest_test_1
Attaching to composetest_test_1
test_1  | total 8
test_1  | drwxr-xr-x    2 1000     users           80 Apr 26 16:47 .
test_1  | drwxr-xr-x    1 www-data www-data      4096 Apr 26 16:49 ..
test_1  | -rw-r--r--    1 1000     users          126 Apr 26 16:48 docker-compose.yml
test_1  | -rw-r--r--    1 1000     users            0 Apr 26 16:46 iam_a_file

Inspect show that when you provide a relative path, docker change it to a full path.

Edit: i also tried with php:5.6-apache, it works.

Upvotes: 3

Related Questions