0% found this document useful (0 votes)
39 views

SSH Into A Container

This document discusses different ways to access running Docker containers. It describes how to SSH into an existing container using docker exec, run commands in containers defined in a docker-compose.yml file, and start new containers to run single commands with docker run. It also covers getting a shell in a build container to perform operations and running commands without a dedicated shell.

Uploaded by

Rpl Marseille
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

SSH Into A Container

This document discusses different ways to access running Docker containers. It describes how to SSH into an existing container using docker exec, run commands in containers defined in a docker-compose.yml file, and start new containers to run single commands with docker run. It also covers getting a shell in a build container to perform operations and running commands without a dedicated shell.

Uploaded by

Rpl Marseille
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

12/04/2019 SSH into a container - DevTools CLI Documentation

Docs » Common Tasks » SSH into a container

SSH into a Container

How do I SSH into a running container


There is a docker exec command that can be used to connect to a container that is already
running.

Use docker ps to get the name of the existing container


Use the command docker exec -it <container name> /bin/bash to get a bash shell in the
container
Generically, use docker exec -it <container name> <command> to execute whatever command
you specify in the container.

How do I run a command in my container?


The proper way to run a command in a container is: docker-compose run <container name>

<command> . For example, to get a shell into your web container you might run docker-compose run

web /bin/bash

To run a series of commands, you must wrap them in a single command using a shell. For
example: docker-compose run

<name in yml> sh -c '<command 1> && <command 2> && <command 3>'

In some cases you may want to run a container that is not de ned by a docker-compose.yml
le, for example to test a new container con guration. Use docker run to start a new container
with a given image: docker run -it <image name> <command>

The docker run command accepts command line options to specify volume mounts,
environment variables, the working directory, and more.

Getting a shell for build/tooling operations


Getting a shell into a build container to execute any operations is the simplest approach. You
simply want to get access to the cli container we de ned in the compose le. The command
docker-compose -f build.yml run cli will start an instance of the phase2/devtools-build image
and run a bash shell for you. From there you are free to use drush , grunt or whatever your
little heart desires.

phase2.github.io/devtools/common-tasks/ssh-into-a-container/ 1/2
Running commands, but not from a dedicated shell
12/04/2019 SSH into a container - DevTools CLI Documentation

Another concept in the Docker world is starting a container to run a single command and
allowing the container stop when the command is completed. This is great if you run
commands infrequently, or don't want to have another container constantly running. Running
your commands on containers in this fashion is also well suited for commands that don't
generate any les on the lesystem or if they do, they write those les on to volumes mounted
into the container.

The drush container de ned in the example build.yml le is a container designed speci cally
to run drush in a single working directory taking only the commands as arguments. This
approach allows us to provide a quick and easy mechanism for running any drush command,
such as sqlc , cache-rebuild , and others, in your Drupal site quick and easily.

There are also other examples of a grunt command container similar to drush and an even
more speci c command container around running a single command, drush make to build the
site from a make/dependency le.

phase2.github.io/devtools/common-tasks/ssh-into-a-container/ 2/2

You might also like