# Execute commands in Docker containers

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

{% hint style="info" %}
Since **magento-scripts\@1.1.0**
{% endhint %}

Executes command in a chosen container.

This command is basically a wrapper on top of [docker exec](https://docs.docker.com/engine/reference/commandline/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](https://docs.create-magento-app.com/getting-started/available-commands/status) command or `docker ps`.

```bash
# Using docker exec

# 1. get container name
docker ps
> ... # docker ps otput

# 2. execute command
docker exec -it <container name> <command>

# Using CMA exec

# 1. execute command
yarn run exec <service name> <command>
> ... # output from command is piped to your terminal
```

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 service names**:

* `mariadb`
* `php`
* `varnish`
* `nginx`
* `ssl-terminator`
* `redis`
* `elasticsearch`

{% hint style="info" %}
If you are using OpenSearch, service name will remain `elasticsearch`.
{% endhint %}

## Usage example

```bash
yarn run exec mariadb

>root@c8f223c3ea92:/# # inside a container with mariadb database

# ctrl + d or type 'exit' and press enter

# this is not alias, but rather service name matching
yarn run exec ma

>root@c8f223c3ea92:/# # inside a container with mariadb database

# custom command to check for nginx service status in container
yarn run exec nginx service nginx status

# expected output
>[ ok ] nginx is running.
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.create-magento-app.com/getting-started/available-commands/exec.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
