简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM