Execute commands in Docker containers

yarn run exec <container name> [commands] or npm run exec -- <container name> [commands]

Executes command in a chosen container.
This command is basically a wrapper on top of docker exec command. It simplifies execution command in docker containers by providing names for docker containers so you don't have to search them by running a status command or docker ps.
1
# Using docker exec
2
3
# 1. get container name
4
docker ps
5
> ... # docker ps otput
6
7
# 2. execute command
8
docker exec -it <container name> <command>
9
10
# Using CMA exec
11
12
# 1. execute command
13
yarn run exec <service name> <command>
14
> ... # output from command is piped to your terminal
Copied!
If you don't want to execute specific command, by default exec command will use bash as a command (and redis-cli for redis container) so you will be connected to the container with interactive shell environment.

Available container names:

  • mysql
  • nginx
  • redis
  • elasticsearch

Usage example

1
yarn run exec mysql
2
3
>[email protected]:/# # inside a container with mysql database
4
5
# ctrl + d or type 'exit' and press enter
6
7
# this is not alias, but rather service name matching
8
yarn run exec m
9
10
>[email protected]:/# # inside a container with mysql database
11
12
# custom command to check for nginx service status in container
13
yarn run exec nginx service nginx status
14
15
# expected output
16
>[ ok ] nginx is running.
Copied!
Last modified 8mo ago