Skip to content

Instantly share code, notes, and snippets.

@samhernandez
Last active April 10, 2017 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samhernandez/4147d349413bf63311e895eea8b4e062 to your computer and use it in GitHub Desktop.
Save samhernandez/4147d349413bf63311e895eea8b4e062 to your computer and use it in GitHub Desktop.
Get the container name from a compose file
# Suppose there is service defined in the docker-compose.yml file
# named `mysql` but it does not have `container_name` defined so
# we don't know what the container name is right now
CONTAINER_NAME=$(docker-compose -f docker-compose.yml ps | grep mysql | awk '{ print $1 }')
echo "Restarting mysql container"
docker stop $CONTAINER_NAME
docker start $CONTAINER_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment