Samuel K.M
Posted on November 4, 2021
While working in docker you may feel as you are locked in a box and you cant do anything inside the box.However docker provides for a way to work inside a container using its cli commands.
Lets say we are running a mongodb image and would like to access the mongo shell. How do you do that?
- Simply Open A New Commandline interface different from where you have spinned up docker.
- Type
docker exec -it mongodb mongo
This command is applicable to any docker container ,even those started using docker-compose. You just need to know two things:
- The Docker Container name
- The command that applies to that container
docker exec -it ContainerName ContainerCommand
So in our prior example:
docker exec -it mongodb mongo
mongodb is the name of our container
mongo is the name used to intialize the mongo shell
This command also applies to services started using the docker compose
command .
Let say you are running a laravel php application on docker this would apply
docker exec -it Laravel php artisan make:controller ShopController
Notice :
Laravel is the name of my container which may vary depwnding on how you have named your container
php artisan make:controller ShopController is a cli command for Laravel
Posted on November 4, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 9, 2024