You can also make a helper script:
New file at the root folder called dc without extension.
Content example. Modify for your needs.
#!/bin/bashtrap"exit" 0
DC="docker compose"# add `-f docker/compose.yml` if it's in another folderif[$# -eq 0 ];then$DC ps -aelif[$1=="up"];then$DC up -delif[$1=="nr"];then
if[$# -gt 1 ];then$DCexec node su node -c"${*:2}"else$DCexec node su node
fi
elif[$1=="npm"];then$DCexec node su node -c"npm ${*:2}"elif[$1=="install"];then$DCexec node su node -c'npm install'elif[$1=="recreate"];then$DC up -d--force-recreate${*:2}elif[$1=="build"];then$DC up -d--force-recreate--build${*:2}else$DC$*fi
Give execute permission with chmod +x ./dc
And now you can run:
./dc to show all containers with status
./dc up to start in detached mode
./dc install to run npm install in the node container as user node
./dc npm install package-name-here to run any npm command inside node container. Works with ./dc npm run start too
./dc nr interactive exec inside node container
./dc nr node index.js run any command inside node container
./dc recreate applies any modifications to docker-compose.yml
./dc recreate node applies modifications to compose, only for node container
./dc build if you have a custom dockerfile, does run dc up with a fresh build.
./dc logs -n 10 -f node - any other docker-compose command works as expected.
👋 Hi there! I'm a passionate developer with a love for solving challenging problems through code. I enjoy exploring new algorithms, optimizing solutions, and continuously learning about new techs.
🧠 AwwyNO | Software Engineer | Clean Code == Clean Conscience
Python| Django | JavaScript | Bash| React| C
I believe in strong backend architecture, smart frontends, and doing things the right way.
Location
Kenya
Education
Bsc. Forensic Science and Software Engineering (ALX)
👋 Hi there! I'm a passionate developer with a love for solving challenging problems through code. I enjoy exploring new algorithms, optimizing solutions, and continuously learning about new techs.
Creating seamless iOS apps with UIKit and SwiftUI. Passionate about transforming ideas into impactful mobile experiences, I stay ahead of the curve in the ever-evolving tech landscape.
Hello, my name is Ehsan Shahid, and I am interested in learning about Modern websites and Web-apps. I am full-stack website developer and currently learning about NestJS.
You can also make a helper script:
New file at the root folder called
dcwithout extension.Content example. Modify for your needs.
Give execute permission with
chmod +x ./dcAnd now you can run:
./dcto show all containers with status./dc upto start in detached mode./dc installto run npm install in the node container as user node./dc npm install package-name-hereto run any npm command inside node container. Works with./dc npm run starttoo./dc nrinteractive exec inside node container./dc nr node index.jsrun any command inside node container./dc recreateapplies any modifications to docker-compose.yml./dc recreate nodeapplies modifications to compose, only for node container./dc buildif you have a custom dockerfile, does run dc up with a fresh build../dc logs -n 10 -f node- any other docker-compose command works as expected.Adding one more
docker system pruneThis will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- unused build cache
This is awesome! Instantly added to github.com/devmount/CheatSheets
Thank you!
@devmount Your Github profile is super cool, bro. Much to learn
Thank you so much 🤗
The most used commands in docker.
Thank for Writing.
Thank you @keshav___dev
Thanks!!
Excellent article, thank you! 💯
Something that made me smile, you can tell that the banner image was created using AI :D
If service is there, why not use it 😉
Thanks man
Hi keshav Sandhu,
Top, very nice and helpful !
Thanks for sharing.
This is incredible.
helpful thanks
Recover shrinking disk space on every build :
Great read. I would just suggest you to use Compose v2, which is without a hyphen:
docker compose up.dev.to/keshav___dev/prisma-recap-e...
Prisma cheat sheet
Helpful thank you!
Very useful. :)
Great read, thank you 👍
Thank. Helpful
This is very helpful 😊
Super helpful! Thanks!
Hamen krna kiah
Can I get PDF of this ..?
Hi there. as a mern stack developer, i launched my first web. Feel free to submit your feedback if it needs improving
codelabs.uz/