Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a new image or share source code in a volume in a docker container in development?

I'm wondering what would be the best practice to update the source code in a docker container that is run within( in JAVA and python). I could either modify my code, create a new image and run a container. In Java, I would also need to compile the code. Another solution would be to just use a volume to share the code between my machine and the container so that each time I modify the behavior of my code I won't need to create a new docker image.

I'm asking all of this for development purposes, not deploying Is there a best practice between these two solutions? What are the pros and cons? Is there a difference for a compiled language like a java compared to python?

like image 263
Pierangelo Calanna Avatar asked Dec 13 '25 04:12

Pierangelo Calanna


2 Answers

You should definitely make a new image instead of sharing the code via a mounted volume. Then whole docker ideology is to produce a self-contained "service", which can be portable across server (i.e. copy the image). Yuo docker file and image build process will track versions of your code, i.e. in your docker file you can pull a specific branch, or you can tag the image with a specific tag. In case of a mounted volume, you never sure what version of your code is actually. run.

Hope this reason alone will help you to decide.

like image 161
Artem Trunov Avatar answered Dec 15 '25 18:12

Artem Trunov


this was my question and I found it in this way For development, you can bind a volume. in this example, I assume you have exposed a port on 3000 also instead of an absolute project address NOTE if you are in the project directory within your shell you can use $(pwd)

docker run -d -p 3000:3000 -v absolute-project-address:/app image-name

also you can add your volume name for storing data

docker run -d -p 3000:3000 -v absolute-project-address:/app -v volumeName:/app/data image-name 

But for the production, you must create an image

like image 25
Amirhossien Salighedar Avatar answered Dec 15 '25 18:12

Amirhossien Salighedar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!