Search code examples
mysqldockerdocker-composejoomlacommit

Docker commit does not actually commit


(I am new to docker so patience please) NOTE: I DO NOT USE VOLUMES so the answers in this question do not apply

  1. I am creating two containers from two docker images (jomla+apache+php and mysql) using the docker-compose file listed at the end. Everything works fine.
  2. I can connect to the Joomla installation page I go through the initial configuration, connect to the database, all is well again. (I can browse to the home & administration pages now). Even the installation folder is removed just fine (mandatory step in joomla). I can see the new files and new database created/modified fine within the containers.
  3. I now commit the two running containers to two new images: docker commit CONTAINER_ID new_image_name
  4. The new images are created fine
  5. I remove the containers with docker-compose down
  6. I modify the docker-compose.yml file to use the newly committed images respectively for joomla and mysql
  7. I issue docker-compose up -d
  8. And here comes the frustration: when I browse to the page, I am back to the Joomla installation page, the config files are gone, the database is empty and installation folder reappeared. In other words, nothing was committed in either image. I even removed the older images to exclude any possibility of accidentally using them.

Why is docker not committing these changes?

If I do manual changes (like docker cp ... or docker exec ... or even inside the container) those stick and are committed just fine. I spent two full days on this, any help is appreciated.

docker-compose.yml:

version: '3.8'

networks:
  frontend:
  backend:

services:

  mysql_db:
    container_name: mysql
    image: mysql_me:latest
    command: mysqld --innodb-buffer-pool-size=20M
    restart: on-failure
    environment:
      MYSQL_DATABASE: 'joomla'
      MYSQL_USER: 'joomla_user'
      MYSQL_PASSWORD: 'JPassword'
      MYSQL_ROOT_PASSWORD: 'RPassword'
      MYSQL_ROOT_HOST: '%'
    ports:
      - '3306:3306'
    expose:
      - '3306'
    networks:
      - backend

  joomla:
    container_name: joomla
    image: joomla_me:latest
    restart: always
    ports:
      - "443:443"
      - "8080:80"
    environment:
      JOOMLA_DB_HOST: 'mysql_db:3306'
      JOOMLA_DB_USER: 'joomla_user'
      JOOMLA_DB_PASSWORD: 'JPassword'
      JOOMLA_DB_NAME: 'joomla'
    links:
      - mysql_db:3306
    networks:
      - frontend
      - backend
    depends_on:
      - mysql_db

Solution

  • Like David Maze pointed out, the original images I am building upon are already using volumes so my custom images are "inheriting" those volumes - even though I am not explicitly declaring any volumes in my own yaml file. Couldn't find that documented anywhere I searched, so I hope this will help other beginners.