Use Docker for development, should I use ADD or VOLUME?

I'm starting to use Docker for projects, and most of these projects run in PHP (some in Nginx / PHP-FPM, some in Apache / PHP as a module).

The fact is, my brain cannot figure out when to use the ADD and VOLUME directives in the Docker file for paths containing the source code.

Here I want to: change the line of code, access the browser in the container port and see the changes. And so on, until everything works as expected, and then I will “add” the code to the machine and distribute it. I think Docker works. I am wrong?

AFAIK, the ADD directive copies files at a given path to the image, and the VOLUME directive simply says that this path will be set by me on the host.

Things that reach me reach me:

  • Add the source code files through ADD, and then enter the -v command at a command prompt to mount the source code in the same path as in ADD.

  • Use VOLUME and process two different Dockerfiles: for container development, and for testing / development and building each as needed (this thing, I think, is counterproductive, and my heart tells me that it should not work that way).

Can someone help me? What does my brain not understand, and should I (and understand) use my Docker knowledge?

+4
source share
3 answers

Th official PHP Image gives examples of two possible workflows.

For production, you can have a Docker file that creates a container containing your code:

FROM php:5.6-apache
COPY src/ /var/www/html/

, :

docker run -it --rm --name my-php-dev -v "$PWD/src":/var/www/html php:5.6-apache
+5

VOLUME , , . , ADD , .

Dockerfiles, env ( : , ADDing ) Docker, Docker Hub ( , , ). - Docker Compose ( , , ) Docker, .

+2

, , VOLUME ( -v). , , ADD, , , , Dockerfiles, , .

, : docker build, VOLUME - , , docker build.

0

All Articles