loading...

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-... [Read Full]
markdown guide
 

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.

 
 
 

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.

 
 

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!

 

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]

 

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.

 

very interesting, thanks for sharing!

 

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.

 
 

run all images

docker start $(docker ps -aq)

stop all images

docker stop $(docker ps -aq)

get a lot of info about docker image when it's running including IP address

docker inspect docker-image-name

other docker commands which I'm most of the time using are: images, image, rm, rmi, container, containers

use docker help command like ex. 'docker help image'

 
 
 

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

 
 

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 :)

 
code of conduct - report abuse