Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quickly switch between docker environments for development?

I have multiple projects that I need to switch in between on a regular basis. The projects are setup via docker-compose, yet some need external containers to be available.

So in order to run docker-compose up -d in a project, I have to switch to a different directory first and start some basic service containers there (shared instances of mysql, redis, and the like).

I do not want to run all the containers in parallel, and for some it is not possible as they they listen on the same port.

What I also find annoying that certain containers need a script to be run inside of them in order to function properly in a development, and I find myself repeating doing the same commands over again just in order to switch to a project.

I think this can be automated, I am just unsure how to tackle this problem.

How can I manage to quickly switch the docker environments? My goal is to just have a one-liner.

like image 947
k0pernikus Avatar asked Oct 28 '25 06:10

k0pernikus


1 Answers

My current workflow now involves desk.

For each project, I have initialized a desk via:

desk edit project_a

and there I run all the steps that I would have done manually, e.g.:

ponysay "INIT PROJECT A"
docker stop $(docker ps -a -q) # stopping all the running containers
cd ~/src/docker-compose/basic-services 
docker-compose up -d
cd ~/src/project_a
docker-compose up -d
docker exec -it project_a_container_name /var/www/project_a/docker/scripts/dev-init.sh

and I switch between the enviornments via:

desk . project_a
desk . project_b

and switching projects now has become quite easy.

like image 103
k0pernikus Avatar answered Oct 29 '25 21:10

k0pernikus