Created
June 9, 2017 12:40
-
-
Save smxsm/67a348b79d5cd4119c24b5902ba56f53 to your computer and use it in GitHub Desktop.
jwilder/nginx-proxy - Check if Docker network and container exist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
########################################################################## | |
# script to check if the jwilder proxy container is already running | |
# and if the ngnix-proxy network exists | |
# run before "docker-compose up -d" if you use nginx-proxy for several projects | |
# see https://github.com/docker/compose/issues/2075 | |
########################################################################## | |
if [ ! "$(docker network ls | grep nginx-proxy)" ]; then | |
echo "Creating nginx-proxy network ..." | |
docker network create nginx-proxy | |
else | |
echo "nginx-proxy network exists." | |
fi | |
if [ ! "$(docker ps | grep nginx-proxy)" ]; then | |
if [ "$(docker ps -aq -f name=nginx-proxy)" ]; then | |
# cleanup | |
echo "Cleaning Nginx Proxy ..." | |
docker rm nginx-proxy | |
fi | |
# run your container in our global network shared by different projects | |
echo "Running Nginx Proxy in global nginx-proxy network ..." | |
docker run -d --name nginx-proxy -p 80:80 --network=nginx-proxy -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy | |
else | |
echo "Nginx Proxy already running." | |
fi |
docker network ls | grep nginx-proxy || docker network create nginx-proxy
Grep might be too broad. Check this:
docker network inspect nginx-proxy &>/dev/null || \
docker network create nginx-proxy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
one-liner for the network - ensuring the network is created: