简体   繁体   中英

MySQL and volumes in Docker

I have an application that runs in a Docker environment. I tried to configure docker volume in a docker-compose file for persisting data written in MySqln while executing docker compose down -v .

Here is my file :

version: "2"
services:
  db:
    container_name: db-server
    image: mysql:5.8
    restart: always
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: p@$$w0rd
      MYSQL_DATABASE: apps
    volumes:
      - /home/john/myapp/volumes-sql:/var/lib/mysql
    networks:
      app_net:
        ipv4_address: 10.1.14.2
  back-end-java:
    container_name: web-server
    build:
      context: .
      dockerfile: Dockerfile-back
    restart: always
    image: web-server:$VERSION
    ports:
      - 8022:8443
    links:
      - db
    networks:
      app_net:
        ipv4_address: 10.1.14.3
networks:
  app_network:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 10.1.14.0/24
        gateway: 10.1.14.1

I recived this message after ran : docker logs db-server : chown: cannot read directory '/var/lib/mysql/': Operation not permitted

How can I resolve this problem ? and how can I use the volume when run docker run or docker up -d

Thank you

John.

Any relation between the permissions on /home/john/myapp/volumes-sql and '/var/lib/mysql/' ??

0 drwxrwxr-x. 2 john john 6 Sep 24 08:10 volumes-sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM