We can't push a docker volume so now what?

After much thought we have found a solution. please let me know your thoughts.

TL;DR;
We were able to use an image to create a volume if needed and kill itself, leaving behind a volume and nothing else.

EXPLANATION
We were able to achieve the result we wanted with the use of volumes in docker-compose, Dockerfile volumes, single layer images, and docker-compose depends_on .

Docker images are not supposed to be large, but making them single layers, or if the final layer is the largest or the layer of concern it becomes much less of an issue.

In my Dockerfile I have:

FROM alpine:latest  
RUN cd some_dir && \  
         wget some_files && \     
         tar xf some_files && \   
         rm -f some_files r  
VOLUME ["some_dir"]

Then in my docker-compose.yml multiple services are declared and all are dependent on a service who’s purpose is to create a container, based on the image the above Dockerfile creates, that attaches it’s volume to a volume all the other conatiners attach to.

in My docker.compose.yml I have:

version: "3.5"  
services:  
  myVolume-service:
    image: volume_image
    command: >
         /bin/sh -c "./do_nothing_and_exit_imediately"
    volumes:
    - compilers:some_dir #same dir as specified in above Dockerfile
  service-a:
    container_name: shell
    image: come_custom_aplication_image
    depends_on:
     - myVolume-service
    volumes:
    - myVolume:/dir/to/mount/myVolume:ro    
    command: >
         /bin/bash -c "./do_service-a_stuff"`
volumes:
  myVolume:

This opens up posisblities for other things such as syncing which if used in combination with healthchecks, allows for updates and anything else that might benifit from being in the volume tot get in them at runtime if rebuilding the volume image isn’t an option.

I will update this if we determine that syncing/healthchecks are usefule

1 Like