Menu

Use the twilio-cli Docker image

The official Docker image for twilio-cli enables you to use twilio-cli in a portable and secure container-based environment without having to manage the installation yourself.

Before you begin

In order to utilize the twilio-cli Docker image, you will need to make sure you have Docker installed and running on your system. For installation instructions, see the Docker website.

Run the Docker image

To run the twilio-cli Docker image with an interactive bash shell, use:

docker run -it --rm twilio/twilio-cli bash

Once the container has finished downloading and you have entered the shell, you can issue commands using twilio-cli. For example:

$ docker run -it --rm twilio/twilio-cli bash

root@1234:/twilio# twilio profiles:list
ID      Account SID                         Active
you     ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  true
main    ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  false

Run commands directly

It is also possible to pass commands directly to the Docker image for single, contained operations. For example, you can check the running version of twilio-cli with the following:

$ docker run -it --rm twilio/twilio-cli twilio --version​
twilio-cli/3.0.0 linux-x64 node-v14.18.1

Provide credentials and configuration

Since the container is cleaned up between each execution, it is useful to pass credentials and configuration directly to the Docker container instead of needing to use twilio login on each run.

Via environment variables

If you have your profile credentials set as environment variables, you can pass them directly to the Docker container. The environment variables will be picked up by the containerized version of twilio-cli:

$ export TWILIO_ACCOUNT_SID=...
$ export TWILIO_API_KEY=...
$ export TWILIO_API_SECRET=...
$ docker run -it --rm \
  -e TWILIO_ACCOUNT_SID \
  -e TWILIO_API_KEY \
  -e TWILIO_API_SECRET \
  twilio/twilio-cli twilio phone-numbers:list

SID                                 Phone Number  Friendly Name
PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  +15558675310  (555) 867-5310

See the Docker run reference guide for more information about setting container environment variables.

Via the file system

Since twilio-cli stores your profile settings on your local file system, it's possible to share those settings with the Docker container by using Volumes. Your profiles will be inherited by the Docker container, without the need to login.

To share your local configuration with the Docker container, mount your system's ~/.twilio-cli directory to the container at /root/twilio-cli using the -v flag. See the Docker run reference guide for more information about the -v flag.

On macOS and Linux, use:

$ docker run -it --rm \
  -v ~/.twilio-cli:/root/.twilio-cli \
  twilio/twilio-cli twilio phone-numbers:list

SID                                 Phone Number  Friendly Name
PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  +15558675310  (555) 867-5310

In Windows with PowerShell, run:

C:\> docker run -it --rm `
  -v $env:userprofile\.twilio-cli:/root/.twilio-cli `
  twilio/twilio-cli twilio phone-numbers:list

SID                                 Phone Number  Friendly Name
PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  +15558675310  (555) 867-5310

If this method fails to find your credentials, they are probably in a deprecated format from twilio-cli v2. Run twilio profiles:port to migrate your credentials, and reattempt the above example.

Run a specific version or tag

There are multiple versions of the twilio-cli Docker image that you can use. To run a specific version, append the desired tag to your docker run command.

There are two types of tags:

  • latest - Sets the latest version of the Docker image, which we recommend. This is the default behavior of docker run, but you can choose to append it explicitly.
    docker run -it --rm twilio/twilio-cli:latest​ bash
  • <major.minor.patch> - Sets the container to run using a specific version of the Docker image.
    docker run -it --rm twilio/twilio-cli:2.36.1 bash​

Update to the latest Docker image

The latest Docker image is only downloaded to your machine on the first execution of docker run. You need to manually pull the latest version of subsequent runs if you wish to use an updated image.

To download the latest Docker image and make it available locally, use:

docker pull twilio/twilio-cli

Next steps

Now that you have the twilio-cli Docker image installed and understand its use:

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Thank you for your feedback!

Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

Sending your feedback...
🎉 Thank you for your feedback!
Something went wrong. Please try again.

Thanks for your feedback!

Refer us and get $10 in 3 simple steps!

Step 1

Get link

Get a free personal referral link here

Step 2

Give $10

Your user signs up and upgrade using link

Step 3

Get $10

1,250 free SMSes
OR 1,000 free voice mins
OR 12,000 chats
OR more