podman-compose icon indicating copy to clipboard operation
podman-compose copied to clipboard

volume gets destroyed and recreated when adding a new stanza to docker-compose.yml

Open anand-siva opened this issue 3 years ago • 1 comments

Describe the bug Podman volume gets nuked and recreated when adding a new stanza to a docker-compose file.

To Reproduce

Here is my docker-compose.yml file

version: "3.9"
services:

  mysql8:
    restart: always
    image: percona/percona-server:8.0.33-aarch64
    volumes:
      - ./config/my_dev8.cnf:/etc/my.cnf.d/my_dev.cnf
      - mysql8-good-data:/usr/local/mysql/data/
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 1
      MYSQL_ROOT_HOST: '%'
    ports:
      - "4306:3306"

volumes:
  mysql8-good-data:
    external: false

Create new DB in mysql

mysql -uroot -P4306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.33-25 Percona Server (GPL), Release 25, Revision 60c9e2c5

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql>
mysql> create database user_database;
Query OK, 1 row affected (0.03 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| user_database      |
+--------------------+
5 rows in set (0.00 sec)

Now add new stanza to docker-compose and run podman-compose up

version: "3.9"
services:

  mysql8:
    restart: always
    image: percona/percona-server:8.0.33-aarch64
    volumes:
      - ./config/my_dev8.cnf:/etc/my.cnf.d/my_dev.cnf
      - mysql8-good-data:/usr/local/mysql/data/
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 1
      MYSQL_ROOT_HOST: '%'
    ports:
      - "4306:3306"

  mongodb:
    restart: always
    image: mongo:4.4.2
    volumes:
      - ./db/:/db-backup/
      - mongodb-good-data:/usr/local/var/mongodb
    ports:
      - "27017:27017"

volumes:
  mysql8-good-data:
    external: false
  mongodb-good-data:
    external: false

podman-compose -f docker-compose.arm64.yml up -d

Now go back into mysql and see that the database was deleted

10:11:48 anandsiva ~/work/podman_bug $ mysql -uroot -P4306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.33-25 Percona Server (GPL), Release 25, Revision 60c9e2c5

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

Expected behavior I expect that the volume podman_bug_mysql8-good-data not to be deleted and recreated. Even in the output command you see it is trying to check for the volume and only recreate if it does not exist

podman volume inspect podman_bug_mysql8-good-data || podman volume create podman_bug_mysql8-good-data ['podman', 'volume', 'inspect', 'podman_bug_mysql8-good-data']

Actual behavior What happens is that the volume podman_bug_mysql8-good-data gets recreated and my data is wiped out. The default should be that the volumes do not get deleted unless you send -v to delete volume

Output

podman-compose and podman version 

podman-compose version
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.5.1
podman-compose version 1.0.6
podman --version
podman version 4.5.1
exit code: 0

podman version

Client:       Podman Engine
Version:      4.5.1
API Version:  4.5.1
Go Version:   go1.20.6
Git Commit:   9eef30051c83f62816a1772a743e5f1271b196d7
Built:        Fri May 26 11:10:12 2023
OS/Arch:      darwin/arm64

Server:       Podman Engine
Version:      4.6.2
API Version:  4.6.2
Go Version:   go1.20.7
Built:        Mon Aug 28 15:39:14 2023
OS/Arch:      linux/arm64

podman info
host:
  arch: arm64
  buildahVersion: 1.31.2
  cgroupControllers:
  - cpuset
  - cpu
  - io
  - memory
  - pids
  - rdma
  - misc
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.7-2.fc38.aarch64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.7, commit: '
  cpuUtilization:
    idlePercent: 99.78
    systemPercent: 0.09
    userPercent: 0.13
  cpus: 12
  databaseBackend: boltdb
  distribution:
    distribution: fedora
    variant: coreos
    version: "38"
  eventLogger: journald
  hostname: localhost.localdomain
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 6.4.12-200.fc38.aarch64
  linkmode: dynamic
  logDriver: journald
  memFree: 7300136960
  memTotal: 12234739712
  networkBackend: netavark
  ociRuntime:
    name: crun
    package: crun-1.8.7-1.fc38.aarch64
    path: /usr/bin/crun
    version: |-
      crun version 1.8.7
      commit: 53a9996ce82d1ee818349bdcc64797a1fa0433c4
      rundir: /run/crun
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +WASM:wasmedge +YAJL
  os: linux
  remoteSocket:
    exists: true
    path: /run/podman/podman.sock
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: false
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: true
  serviceIsRemote: true
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.2.1-1.fc38.aarch64
    version: |-
      slirp4netns version 1.2.1
      commit: 09e31e92fa3d2a1d3ca261adaeb012c8d75a8194
      libslirp: 4.7.0
      SLIRP_CONFIG_VERSION_MAX: 4
      libseccomp: 2.5.3
  swapFree: 0
  swapTotal: 0
  uptime: 2h 52m 19.00s (Approximately 0.08 days)
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  search:
  - docker.io
store:
  configFile: /usr/share/containers/storage.conf
  containerStore:
    number: 7
    paused: 0
    running: 6
    stopped: 1
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev,metacopy=on
  graphRoot: /var/lib/containers/storage
  graphRootAllocated: 321427587072
  graphRootUsed: 18268368896
  graphStatus:
    Backing Filesystem: xfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "true"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 17
  runRoot: /run/containers/storage
  transientStore: false
  volumePath: /var/lib/containers/storage/volumes
version:
  APIVersion: 4.6.2
  Built: 1693251554
  BuiltTime: Mon Aug 28 15:39:14 2023
  GitCommit: ""
  GoVersion: go1.20.7
  Os: linux
  OsArch: linux/arm64
  Version: 4.6.2

anand-siva avatar Sep 11 '23 14:09 anand-siva

Are you sure the volume is getting deleted, and not that you are mounting it in the wrong location such that your database isn't stored in the volume?

Code snippets found with https://github.com/search?q=percona-server+docker-compose.yaml+volumes&type=code and the percona documentation https://hub.docker.com/r/percona/percona-server both show examples storing data in /var/lib/mysql and you are using /usr/local/mysql/data/ .

I think what

podman volume inspect podman_bug_mysql8-good-data || podman volume create podman_bug_mysql8-good-data
['podman', 'volume', 'inspect', 'podman_bug_mysql8-good-data']

is saying is that (similar to bash) it will create it if podman volume inspect returns nonzero, and I assume the line after that, with no create following it, shows that it isn't actually creating it again. - but I could be wrong, I didn't check the source.

deliciouslytyped avatar Oct 22 '23 22:10 deliciouslytyped