简体   繁体   中英

Docker MariaDB volume not found in container?

This docker-compose.yml file works fine:

version: '3'
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: docker-test
    container_name: docker-test
    ports:
      - 9000:80
    volumes:
      - '/var/www/docker-test/:/srv/app/'      
  db:
    image: mariadb:10.4
    container_name: docker-test-db
    ports:
      - 33061:3306
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    volumes:
      - '/docker-db-data/docker-test/:/var/lib/mysql/'

The volume in the host is created fine ( /docker-db-data/docker-test/ ) but when I "SSH" to the container, I can't seem to find /var/lib/mysql Eg,

[root@localhost docker]# docker exec -it docker-test bash
root@2d03e775f531:# ls /var/lib/mysql
ls: cannot access '/var/lib/mysql': No such file or directory

Is this expected? If not, where is it actually located?

The volumes: attach to specific containers. Your docker exec docker-test command attaches to the app: container, but you actually want to attach to the db: container, which you've named docker-test-db . If you add that -db on the end, it will work:

docker exec docker-test-db ls /var/lib/mysql

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