4

I'm new to docker and I get a strange error when building my first containers. I'm using WSL2 if that matters.

Here is the part that's causing it :

  # MySQL Service
  mysql:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: usr_data
    volumes:
      - ./.docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
      # - ./.docker/mysql/ohmy.cnf:/etc/mysql/conf.d/my.cnf
      - ./.docker/test/test.txt:/tmp/test/test.txt
      - mysqldata:/var/lib/mysql
    healthcheck:
      test: mysqladmin ping -h 127.0.0.1 -u root --password=MYSQL_ROOT_PASSWORD
      interval: 5s
      retries: 10

Both files my.cnf and ohmy.cnf exist and have the same content.

When I use docker-compose up -d I get the error :

ERROR: for mysql  Cannot create container for service mysql: not a directory

When I uncomment the ohmy.cnf line and comment the my.cnf line I get no errors and it builds just fine. It also works great with the little test.txt I made.

I fail to see the difference between the two, and while it may work with my little workaround, I'd like to understand what is causing the error in the first place.

Thank you for your time.

Edit : Here's my ./.docker

./.docker
├── mysql
│   ├── db
│   │   └── db.sql
│   ├── my.cnf
│   └── ohmy.cnf
├── nginx
│   └── conf.d
│       └── php.conf
├── php
│   └── Dockerfile
└── test
    └── test.txt

6 directories, 6 files
yhuet
  • 41
  • 1
  • 3
  • Can you try changing the folder name from `.docker` to `docker` ? – frank_lee Apr 28 '21 at 03:50
  • 1
    Renaming from `docker` to `.docker` solved error `Cannot create container for service : not a directory` for me, but I can't understand why :-( – circulosmeos May 12 '21 at 14:05
  • Encountered this problem on `wsl2`, switch to `windows-terminal` `PowerShell` then everything works fine. I guess this is a problem caused by docker. – Jay Jun 12 '21 at 03:42
  • as @circulosmeos, my file was also inside a folder named *docker*, so giving it a different name solved the same issue for me. – Pherrymason Sep 26 '21 at 16:12

2 Answers2

3

In WSL 2 I updated docker compose to use $PWD instead of a relative path for volumes:

volumes:
  - $PWD/logs:/var/log/docker:delegated
Alin Pop
  • 129
  • 1
  • 7
  • This was my issue as well. Updated to wsl --version WSL version: 0.50.2.0 Kernel version: 5.10.74.3 WSLg version: 1.0.29 Windows version: 10.0.22000.318 – Elan Hasson Nov 17 '21 at 19:20
2

Delete the volumes from /var/lib/docker/volumes/[your-volumes]. Run the below commands

  1. docker volume prune Remove all unused local volumes. Unused local volumes are those which are not referenced by any containers.
  2. docker system prune Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.
Ashok
  • 2,259
  • 12
  • 25
  • 3
    Thank you for your answer. `docker volume prune` did nothing. `docker system prune` deleted a whole lot of things but i still get the exact same error. – yhuet Apr 24 '21 at 07:08