Nagasrinivas Vemula
Nagasrinivas Vemula

Reputation: 3

how to pass container id to docker exec through output of another cmd

i want to pass docker container id from output of another linux command

example (as pseudo-code):

save output of docker ps cmd to a file
docker ps > docker.log
grep only container id : awk 'FNR == 2{print $1}' 

now i want to pass the output of awk cmd to docker exec

like docker exec -it awk 'FNR == 2{print $1}' /bin/bash (i am not able to pass container id through cmd)

this is to automate a process that needs ssh in docker containers

Upvotes: 0

Views: 1190

Answers (1)

azbarcea
azbarcea

Reputation: 3657

Why not something like this:

docker exec -it $(docker ps | grep dac705114996 | awk '{print $1}') /bin/sh

As you can see, in order to pass the container-id to the docker exec cmd, you need to substitute the container-id with $(command that extracts the container-id) Command Substitution (more official docs)

Upvotes: 1

Related Questions