docker run shell code example

Example 1: docker interactive shell

docker exec -it [containerid/name] [shell]

#Example
docker exec -it fa80b69 bash
#if its an apline container use "sh" instead of "bash"

Example 2: how to bash into docker container

docker exec -it nginx /bin/bash

Example 3: docker exec bash

//For executing commands in the container
docker exec -it <CONTAINER_NAME> bash

Example 4: docker run command on container

sudo docker exec -it <container name> <command>

Example 5: how to execute docker command in shell script

echo -n "enter type compose command ? "
read type

[[ "$type" ]] && docker-compose $type;

Example 6: docker how to run existing container

docker start <container-name/ID>

Tags: