Run a command in a running container with docker exec.
# To enter an interactive shell session on an already-running container:
docker exec --interactive --tty <container_name> </bin/bash>
# To run a command in the background (detached) on a running container:
docker exec --detach <container_name> <command>
# To select the working directory for a given command to execute into:
docker exec --interactive -tty --workdir <path/to/directory> <container_name> <command>
# To run a command in background on existing container but keep 'stdin' open:
docker exec --interactive --detach <container_name> <command>
# To set an environment variable in a running bash session:
docker exec --interactive --tty --env <variable_name>=<value> <container_name> </bin/bash>
# To run a command as a specific user:
docker exec --user <user> <container_name> <command>