DEV Community

Cover image for 10 docker-compose and docker commands that are useful for active development

10 docker-compose and docker commands that are useful for active development

Lina Rudashevski on July 25, 2019

Sure you might need other ones but I've found over time that these are the only ones I need or use on a regular basis, and I use Docker and docker-...
Collapse
 
simlu profile image
Lukas Siemon

I would like to throw this one in:

docker run -u`id -u`:`id -g` -v $(pwd):/user/project -v ~/.aws:/user/.aws -v ~/.npmrc:/user/.npmrc -w /user/project -it --entrypoint /bin/bash circleci/node:12

Great if you need to run a bash shell in the current directory with e.g. Node 12. Replace docker image as needed.

This also links the aws and npm config into the docker container. Adjust config link through as needed.

Collapse
 
aduranil profile image
Lina Rudashevski

nice! tks for sharing this

Collapse
 
moonsmile profile image
Nguyễn Minh Tuấn

so cool <3

Collapse
 
dploeger profile image
Dennis Ploeger

Additionally,

docker system prune --volumes

will also remove old volumes, that aren't connected to any currently running container. However, be cautious as this might lead to data loss.

Collapse
 
aduranil profile image
Lina Rudashevski

nice! tks for sharing this!

Collapse
 
sairoko12 profile image
Cristian Benavides Jimenez • Edited

Another powerful commands

Stop and clean up your docker-compose services (because yolo):

docker-compose down -v --rmi all

Build and start services in single line:

docker-compose up --build

Build and start in background:

docker-compose up -d --build

Run command with docker-compose:

# docker-compose exec [service_name] [command]
docker-compose exec django python manage.py shell

See the logs an specific service

docker-compose logs -f [service_name]

Enjoy!

Collapse
 
oreynaldocl profile image
Oscar Callisaya

Good commands, for log I like to add --tail in order to avoid to see only last X logs
docker-compose logs -f --tail [number] [service_name]

Collapse
 
flexdinesh profile image
Dinesh Pandiyan

This is an excellent list and very helpful. Thanks Lina.

I will also add one more of my frequent commands to the list.

docker-compose up --build

This brings the container up and builds if there are changes. This is a shorthand for docker-compose build and docker-compose up together. Comes in handy when you're making changes to your compose file.

Collapse
 
aduranil profile image
Lina Rudashevski

nice one! tks

Collapse
 
jillesvangurp profile image
Jilles van Gurp • Edited

I came across something called lazydocker a few weeks. It's a command line ui for managing docker and docker-compose. Very handy for managing your local containers.

Collapse
 
aduranil profile image
Lina Rudashevski

very interesting, thanks for sharing!

Collapse
 
rzulty profile image
Piotr Grzegorzewski

It's a great list. I use some of them.

As for the tool with UI to manage/monitor docker images and containers, I use Portainer :)

Collapse
 
aduranil profile image
Lina Rudashevski

thank you! :)

Collapse
 
aduranil profile image
Lina Rudashevski

helpful - thank you so much!

Collapse
 
taragrg6 profile image
taragurung

Though, I have used docker for more than couple of years. I was not aware of the second one. Thanks for sharing

Collapse
 
aduranil profile image
Lina Rudashevski

i’m glad it was helpful!

Collapse
 
lewiskori profile image
Lewis kori

Great write up!

Collapse
 
aduranil profile image
Lina Rudashevski

thank you! :)