skip to Main Content

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

3

Answers


  1. 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.
    Login or Signup to reply.
  2. In WSL 2 I updated docker compose to use $PWD instead of a relative path for volumes:

    volumes:
      - $PWD/logs:/var/log/docker:delegated
    
    Login or Signup to reply.
  3. restarting my laptop helped in my special case, the other commands did not

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search