0

I have a web server program which requires pdf files from owncloud server. I'm making installation code via docker-compose & docker hub. I use Ubuntu 20.04LTS and Docker Compose v2.1.0.

Here is the process

  1. store pdf files and create public links in owncloud docker container(under /var/www/owncloud/data)
  2. create new images(both owncloud, mariadb) and tags from container by code below
docker commit 5cba8bf76904
docker tag 9315184e23f5 DOCKERID/docker-mariadb
docker push DOCKERID/docker-mariadb
  1. pull those images in another new fresh Ubuntu server, using docker-compose up

After this process, when I connect to owncloud, running on a new fresh ubuntu server, there are no pdf files and all those configs are intialized (owncloud account, mariadb database configs) and the owncloud start-up page(config admin account and database page) is opened.

My docker-compose, Dockerfiles are below(related parts only)

docker-compose.yml

  owncloud:
    #build: ./dockerfiles/owncloud/
    image: "dockerhubid/docker-owncloud"
    container_name: chatbot_owncloud
    restart: always
    networks:
      - chatbot_network
    depends_on:
      - mariadb
    volumes:
      - 'owncloud_php:/var/www/owncloud'
    command: php-fpm7.4 -F -R

  mariadb:
    # build: ./dockerfiles/mariadb/
    image: dockerhubid/docker-mariadb
    container_name: mariadb
    restart: always
    expose:
      - '3306'
    networks:
      - chatbot_network
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_USER=owncloud
      - MYSQL_PASSWORD=password
      - MYSQL_DATABASE=owncloud
    command: ["--max-allowed-packet=128M", "--innodb-log-file-size=64M"]

  nginx:
    #build: ./dockerfiles/nginx/
    image: "dockerhubid/docker-nginx"
    container_name: chatbot_nginx
    restart: always
    depends_on:
      - owncloud
    volumes:
      - ./dockerfiles/certbot/conf:/etc/letsencrypt
      - ./dockerfiles/certbot/www:/var/www/certbot
    volumes_from:
      - 'owncloud:ro'
    networks:
      - chatbot_network
    ports:
      - '80:80'
      - '3000:3000'
      - '8883:8883'
      - '8884:8884'
    command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"

  certbot:
    image: certbot/certbot
    container_name: chatbot_certbot
    networks:
      - chatbot_network
    volumes:
      - ./dockerfiles/certbot/conf:/etc/letsencrypt
      - ./dockerfiles/certbot/www:/var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"

owncloud Dockerfile

FROM ubuntu:20.04

EXPOSE 9000
ARG DEBIAN_FRONTEND=noninteractive


# dependencies
RUN apt update && apt upgrade -y
RUN apt install -y php-bz2 php-curl php-gd php-imagick php-intl php-mbstring php-xml php-zip php-mysql php-fpm wget zip vim

# owncloud
RUN wget https://download.owncloud.org/community/owncloud-10.5.0.zip
RUN unzip owncloud-10.5.0.zip -d /var/www/
RUN rm /owncloud-10.5.0.zip
WORKDIR /var/www/owncloud
RUN chown www-data:www-data -R /usr/bin/php /var/www/owncloud/
RUN chmod -R 755 /var/www/owncloud/

# php-fpm setup
RUN sed -i 's+/run/php/php7.4-fpm.sock+9000+g' /etc/php/7.4/fpm/pool.d/www.conf

ADD init.sh /docker-entrypoint-initdb.d/
RUN chmod 755 /docker-entrypoint-initdb.d/init.sh

mariadb Dockerfile

from mariadb:10.5

EXPOSE 3306
ARG DEBIAN_FRONTEND=noninteractive
USER root

ADD init.sql /docker-entrypoint-initdb.d/
RUN chmod 755 /docker-entrypoint-initdb.d/init.sql

How can I maintain those files and public links?
Why are those things removed after docker hub push&pull?

I tried it with the owncloud official image first, but by my investigation official image stores data in external docker volume.
I thought that's why my data is gone after docker push&pull.
so I'm trying it by manual installation.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • Wait, you're storing your data in the owncloud __image__? Why? Thats what volumes are for. – tkausl Jul 19 '22 at 06:41
  • like i said i'm docker beginner. how can i maintain docker volumes after push & pull? it should be exists on new fresh ubuntu server. – sanghyeup lee Jul 19 '22 at 06:44
  • I suppose you're looking for this: https://stackoverflow.com/questions/26331651/how-can-i-backup-a-docker-container-with-its-data-volumes#:~:text=To%20backup%20a%20data%20volume,data%20for%20a%20MySQL%20server. – tkausl Jul 19 '22 at 06:45
  • looks like i have to backup & restore docker volume by my self. and docker push & pull not provide it. am i correctly understand? – sanghyeup lee Jul 19 '22 at 06:51
  • Committing the container _would_ work, if your data weren't in a volume. Volumes are not part of images. Manually transferring the volume seems to be the best option. – tkausl Jul 19 '22 at 06:53
  • Committing the container is pretty much never a best practice and leads to non-reproducible images (and as @tkausl indicates it usually does not include the data). If you already have the Dockerfiles for the images, you shouldn't need the `docker commit` step at all. – David Maze Jul 19 '22 at 10:25

0 Answers0