When I modify a mysql service in a docker-compose file, then try to apply the changes by running
docker-compose stop/up/restart commands, I often have it throw the following error:
$ docker-compose up -d Recreating mysql_1 ... Recreating mysql_1 ... error ERROR: for mysql_1 Cannot create container for service mysql: Duplicate mount point: /var/lib/mysql ERROR: for mysql Cannot create container for service mysql: Duplicate mount point: /var/lib/mysql
I’ve been searching Google with several different searches trying to figure out what exactly is going on, but so far I haven’t hit on the magic words…
It seems like docker-compose is trying to create a new volume and use it when the old volume is still around. What I don’t understand is why it’s trying to create a new volume in the first place. The whole point of volumes is to keep the data around so it can used again…
Can anyone explain what’s going on?
My docker-compose.yml looks something like this:
version: "3.3" volumes: mysql_data: networks: appnet: driver: bridge driver_opts: com.docker.network.bridge.name: appnet secrets: dbhost: file: ./secrets/dbhost dbname: file: ./secrets/dbname dbpass: file: ./secrets/dbpass dbport: file: ./secrets/dbport dbtype: file: ./secrets/dbtype dbuser: file: ./secrets/dbuser dbrootpass: file: ./secrets/dbrootpass selfurlpath: file: ./secrets/selfurlpath services: app: image: registry.gitlab.com/jerrac/app/app_app:latest container_name: app_app ports: - 127.0.0.1:3050:80 networks: - appnet depends_on: - app_mysql restart: always secrets: - dbhost - dbname - dbpass - dbport - dbtype - dbuser - selfurlpath app_mysql: image: mysql:5 container_name: db_app volumes: - type: volume source: mysql_data target: /var/lib/mysql - type: bind source: ./datamount target: /srv environment: MYSQL_ROOT_PASSWORD_FILE: /run/secrets/dbrootpass MYSQL_DATABASE: app MYSQL_USER: app MYSQL_PASSWORD_FILE: /run/secrets/dbpass networks: - appnet restart: always secrets: - dbname - dbpass - dbuser - dbrootpass
I can get it to start again by deleting the old volume. But that’s hardly something I can do when I have real data in it… Oh, and I’ve run into this multiple times on several different projects.
Edit: Oops, forgot to add this info:
$ docker-compose version docker-compose version 1.20.1, build 5d8c71b docker-py version: 3.2.1 CPython version: 2.7.12 OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016 $ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"
Steps to reproduce:
- Create docker-compose project with a mysql container that mounts a named volume.
- docker up -d
- Modify the mysql service.
- docker-compose stop
- docker-compose up -d
- Or just docker-compose restart.
Issue type: Support request. I’m pretty sure I’m just not understanding how to do something correctly.