docker-magento2 icon indicating copy to clipboard operation
docker-magento2 copied to clipboard

once i docker-compose down i lose all my settings

Open TheSearcher opened this issue 6 years ago • 8 comments

i was able to spin a magento2 version with docker-compose up -

however, once i docker-compose down i lose everything.

is this how its set up to be or did i do something wrong.

thank you

TheSearcher avatar Jul 16 '19 17:07 TheSearcher

Try docker-compose stop instead.

tomhrtly avatar Sep 12 '19 09:09 tomhrtly

Is there any other solution for this? Maybe adding extra volume for Magento host data will solve the problem.

krskibin avatar Oct 10 '19 07:10 krskibin

You must add volumes to the web service.

Edit the docker-compose.yml file as follows.

version: "3.0"
services:
  web:
    image: alexcheng/magento2
    ports:
      - "80:80"
    links:
      - db
    volumes:
      - web-file:/var/www
    env_file:
      - env
  db:
    image: mysql:5.7
    volumes:
      - db-data:/var/lib/mysql
    env_file:
      - env
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - "8580:80"
    links:
      - db
volumes:
  db-data:
  web-file:

osmansafak avatar Oct 17 '19 20:10 osmansafak

Unfortunetly, @osmansafak doesn't work. With your docker-compose config I can't even import data running install-sampledata command. It shows me some erros with authentication and so on :disappointed:.

krskibin avatar Oct 18 '19 10:10 krskibin

I got the same problem.

And it's very strange. Using volumes actually intends to not have it, but... ((

Gorynych avatar Dec 08 '19 22:12 Gorynych

@osmansafak hi. can you raise this question/issue on https://magento.stackexchange.com/ and i will show you how to fix the error

TheSearcher avatar Dec 09 '19 10:12 TheSearcher

I had a similar problem.

After running docker-compose up -d and docker exec -it <container-id> install-magento everything worked fine. As soon as I ran docker-compose down and started to re-run the containers, a database error occured (could not find table). I did solve it by adapting the db volume destination from db-data:/var/lib/mysql/data to db-data:/var/lib/mysql and adding external: true to both named volumes. Therefore I had to create them before running docker-compose up -d with the commands docker volume create --name=magento-data and docker volume create --name=db-data. I am using external: true mainly since I had some issues in the past whilst referencing named volumes when project names changed, it might be not critical to solve the issue above. For the sake of completeness, you find my docker-compose.yml below:

version: '3'
services:
  web:
    image: alexcheng/magento2
    ports:
      - "80:80"
    links:
      - db
    volumes: 
      - magento-data:/var/www/html  
    env_file:
      - env
  db:
    image: mysql:5.6.23
    volumes:
      - db-data:/var/lib/mysql
    env_file:
      - env
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - "8580:80"
    links:
      - db     
volumes:
  magento-data:
    external: true
  db-data:
    external: true

Maybe this helps anybody. If this is a common problem it might worth a pull request.

philologos avatar Feb 17 '20 10:02 philologos

If you want to control where the data goes, an alternative is (at the end of docker-compose.yml):

volumes:
  magento-data:
  db-data: 
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/data/magento/db'

This is in addition to db-data:/var/lib/mysql

mverleg avatar May 19 '20 20:05 mverleg