Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker development workflow

What's the proper development workflow for code that runs in a Docker container?

Solomon Hykes said that the "official" workflow involves building and running a new Docker image for each Git commit. That makes sense, but what if I want to test a change before committing it to the Git repo?

I can think of two ways to do it:

  1. Run the code on a local development server (e.g., the Django development server). Edit a file; test on the dev server; make a Git commit; rebuild the Docker image with the new code; test again on the local Docker container.

  2. Don't run a local dev server. Instead, build and run a new Docker image each time I edit a file, and then test the change on local Docker container.

Both approaches are pretty inefficient. Is there a better way?

like image 824
Joe Mornin Avatar asked Sep 20 '15 00:09

Joe Mornin


People also ask

What is Docker & Docker workflow?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.

Can I use Docker for development?

Docker is a tool designed to make it easier for developers to develop, ship, and run applications by using containers. Containers allow devs to package an application with all of its requirements and configurations, such as libraries and other dependencies and deploy it as a single package.


1 Answers

A more efficient way is to run a new container from the latest image that was built (which then has the latest code).

You could start that container starting a bash shell so that you will be able to edit files from inside the container:

docker run -it <some image> bash -l

You would then run the application in that container to test the new code.

Another way to alter files in that container is to start it with a volume. The idea is to alter files in a directory on the docker host instead of messing with files from the command line from the container itself:

docker run -it -v /home/joe/tmp:/data <some image>

Any file that you will put in /home/joe/tmp on your docker host will be available under /data/ in the container. Change /data to whatever path is suitable for your case and hack away.

like image 59
Thomasleveil Avatar answered Sep 30 '22 16:09

Thomasleveil