简体   繁体   中英

How can I use an ephemeral volume for a Docker container using an official MySQL image with docker-compose?

I'm using an official MySQL docker image ( https://github.com/docker-library/mysql/blob/3288a66368f16deb6f2768ce373ab36f92553cfa/5.6/Dockerfile ) with docker-compose and I would like its data to be wiped out upon restart. The default is that it retains its data between container restarts.

Here's my docker-compose.yml:

version: "2"
services:
  mydb:
    image: mysql:5.6
    environment:
        MYSQL_ROOT_PASSWORD: foo

When I use docker inspect on my container it shows its location on the host machine. How can I instead have it store the data inside the container? I do not want it to persist.

When using docker-compose , the containers are not removed on docker-compose stop (or ctrl-c, or any other kind of interrupt/exit). Thus, if you're stopping the container, it's still going to exist the next time you start.

What you want is docker-compose down which, according to the docs will "Stop and remove containers, networks, images, and volumes". Note that only containers and networks are removed by default - you need to specify a command-line switch if you want to remove images or volumes.

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