Aley February 2016

How to change VOLUME to COPY in Docker?

My workflow consists of three stages:

  1. development
  2. staging
  3. production

The docker configuration on all three platforms is almost the same, except 1 difference. On development I mount the project directory via VOLUME instead of copying it via COPY.

Now I wonder what's better practice?

Create a Dockerfile for each stage like so

project/
    .docker
        development
            apache-php
                Dockerfile
                vhosts.conf
            mariadb
                Dockerfile
        staging
            apache-php
                Dockerfile
                vhosts.conf
            mariadb
                Dockerfile
        etc.

or somehow conditionaly change VOLUME to COPY, but I have no idea how this should work.

Answers


michaelbahr February 2016

Use inheritance

Create a base image that does not cover the COPY/VOLUME step and then make dev-, test- and production Dockerfiles that base on your base image.

Example

Base Dockerfile

FROM ubuntu:14.04
RUN echo test >> /important.txt

Then build the base image so it may be referenced by the other Dockerfiles: docker build -t baseimage .

Dev Dockerfile

FROM myrepo:baseimage
VOLUME someVolume

Build and run.

Prod Dockerfile

FROM myrepo:baseimage
COPY src dest 

Build and run.

Interesting

Volumes will override conatiner files if used like that:

docke run -it -v ~/some.txt:/some/container/folder

Post Status

Asked in February 2016
Viewed 1,715 times
Voted 12
Answered 1 times

Search




Leave an answer