Execute commands and interact with your cloud containers

A two part barge with stacks of shipping containers on board travels down the Rhine in Germany

As the owner of a web project, you may want to directly access your production site to run developer tools. Historically, many of us would access a live site using SSH for direct shell access on a single static server for traditional hosting. Some hosting providers give limited access to run single commands from a local command line, or start a remote shell session with more complicated commands, but there are delays and it can be a bit like fiddling around in the dark. Add some Kubernetes-based, containerized hosting into the mix and it can feel really intimidating and complicated.

With the release of DDEV-Live CLI version 0.9.2 and API v 0.7.1 you now have the option of initiating an interactive session with a site on our Kubernetes-based hosting platform. We handled the complicated parts so you don’t need to understand the container architecture that holds your project— just connect, navigate around inside the project, and use your command line tools as usual. 

How do I run commands on a remote host?

Previously, in order to run command line tools on a project in a DDEV-Live environment such as production or Preview, you could run a single command using ddev-live exec. (For those of you familiar with the DDEV-Local ddev exec command, this is similar behavior that allows you access inside the web container.) Each command was run individually, and it was difficult to observe the results of the command. Commands could take an unknown period of time to execute, resulting in a loss of momentum, productivity, and even causing a little frustration.

These direct commands are still available and have plenty uses, for example if you just want to set configuration or trigger a single command such as:

ddev-live exec mysite -- drush cr

Until now, running these commands could take several minutes, and the DDEV-Live CLI gave minimal feedback. This is because any command sent using ddev-live exec created what’s called a “job” in the backend on our platform, which would enter a scheduling queue and eventually would be executed. Once the job was actually triggered, the command would run in the expected amount of time, so the delay was just in how the command passed from the user to the project. Good news! We’ve found a better way.

Interactive exec for production containers

Now, the ddev-live exec command consumes our API, which gives everyone more options and flexibility. The exec command itself is faster as a single command and it offers an exciting new interactive mode! Check it out: start a session with ddev-live exec mysite --i [command] and the CLI will start a bidirectional stream of command output between your terminal and the Kubernetes pod where your project lives. The flag --i runs the exec command as an interactive session. Omit it to run a single command as non-interactive.

Instead of waiting for a scheduled “job” to run somewhere in Kubernetes, commands execute right away in both interactive and non-interactive modes. Thanks to the API, you will not connect directly to the pod in Kubernetes, you connect to an API server which brokers everything you type to Kubernetes:

Client <====> API Server <===> Kubernetes

“That was a bunch of words!” you say. Here’s a more specific, super simple, example: run ddev-live exec mysite --i bash. Now you have a shell session open, you’re in the docroot for your project, and you can list files to prove it: 

Screenshot of command line when running `ddev-live exec test-wp --i bash`. A prompt for the remote container appears, and we show listing the files in that directory.

While you’re here, you can start to do all kinds of fun stuff and quickly interact directly with your tools and files. For WordPress users, WP-CLI is available in the container:

www-data@test-wp-5568574998-7mcbc:~/html$ wp cli version
WP-CLI 2.4.0

Other developer tools and tasks in interactive exec mode: 

  • Inspect sites/default/files. 
  • Inspect code. 
  • See what CMS version is live. 
  • Inspect PHP configuration in /etc/php/<version>. 
  • Confirm PHP major and minor version with php --version
  • Remove files in sites/default/files that shouldn’t be there.
  • Observe a deployment and check whether Composer downloaded the right files to the right places.
  • Explore (and alter) the database with drush sql-cli.
  • Check what code commit is deployed with git log.
  • Top Drush commands like drush cr and drush uli.

With DDEV-Live, you can now initiate an interactive session with your project on production and interact with developer tools in a natural command-line context. You can go ahead and run the commands you need to maintain and administer your project without delays or needing to pull and push entire site updates in order to accomplish simple interactive tasks.

Run commands on production websites

DDEV solves the difficulty of using developer tools on projects in hosted containers and the delay of waiting for individual commands to execute by offering an interactive command line connection to the production server that gives the end user the ability to work directly on their own live projects. That leads to saved time, increased velocity, and the flexibility to work with your projects the way you need to. 

tl;dr – Sign up for a free trial with a DDEV-Live personal account, set up your workspace, spin up a site from a repository on your GitHub account, and try running ddev-live exec newSiteName --i bash. Please let us know how it goes and what else you need! 

Share this post: