Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 969
william Avatar asked Oct 17 '25 03:10

william


1 Answers

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.

like image 115
Kryten Avatar answered Oct 18 '25 21:10

Kryten