Docker exec command without the container ID

Yes, you can do this by naming the container with --name. Note that your command with container/container is likely referencing an image name and not the container.

➜  ~ docker run --name my_nginx -p 80:80 -d nginx
d122acc37d5bc2a5e03bdb836ca7b9c69670de79063db995bfd6f66b9addfcac

➜  ~ docker exec my_nginx hostname
d122acc37d5b

Leave a Comment