Myamotooo
Myamotooo

Reputation: 141

Override a volume when Building docker image from another docker image

sorry if the question is basic but would it be possible to build a docker image from another one with a different volume in the new image? My use case is the following:

  1. Start From image library/odoo (cfr. https://hub.docker.com/_/odoo/)
  2. upload folders into the volume "/mnt/extra-addons"
  3. build a new image, tag it then put it in our internal image repo

how can we achieve that? I would like to avoid putting extra folders into the host filesystem

thanks a lot

Upvotes: 2

Views: 1277

Answers (2)

Rory Savage
Rory Savage

Reputation: 63

This approach seems to work best until the Docker development team adds the capability you are looking for.

Dockerfile

FROM percona:5.7.24 as dbdata
MAINTAINER [email protected]
FROM centos:7
USER root
COPY --from=dbdata / /

Do whatever you want . This eliminates the VOLUME issue. Heck maybe I'll write tool to automatically do this :)

Upvotes: 2

bluescores
bluescores

Reputation: 4677

You have a few options, without involving the host OS that runs the container.

  1. Make your own Dockerfile, inherit from the library/odoo Docker image using a FROM instruction, and COPY files into the /mnt/extra-addons directory. This still involves your host OS somewhat, but may be acceptable since you wouldn't necessarily be building the Docker image on the same host you were running it.

  2. Make your own Dockerfile, as in (1), but use an entrypoint script to download the contents of /mnt/extra-addons at runtime. This would increase your container startup time since the download would need to take place before running your service, but no host directories would need be involved.

Personally I would opt for (1) if your build pipeline supports it. That would bake the addons right into the image, so the image itself would be a complete, ready-to-go build artifact.

Upvotes: 0

Related Questions