Skip to content

Instantly share code, notes, and snippets.

@stevobengtson
Last active September 2, 2016 23:39
Show Gist options
  • Save stevobengtson/f2e999afbbd1d5ad91357f8cf38950c5 to your computer and use it in GitHub Desktop.
Save stevobengtson/f2e999afbbd1d5ad91357f8cf38950c5 to your computer and use it in GitHub Desktop.
#!/bin/bash
APP_NAME=$1
PORT=$2
: ${PORT:=4000}
echo "Creating a Phoenix app called $APP_NAME in docker with the port $PORT."
docker run -it --rm -v "$PWD":/code -w /phoenix stevobengtson/vt-phoenix-docker mix phoenix.new /code/$APP_NAME
cd $1
# Change the database connection
sed -i -e 's/hostname: "localhost"/hostname: "db"/g' config/dev.exs
sed -i -e 's/hostname: "localhost"/hostname: "db"/g' config/test.exs
cat > startup.sh << EOF
#!/bin/bash
mix local.hex --force
mix local.rebar --force
mix phoenix.server
EOF
cat > docker-compose.yml << EOF
version: '2'
services:
db:
image: postgres:9.4
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=${APP_NAME}_dev
# alpine based version to keep it tiny
redis:
image: redis:alpine
expose:
- 6379
web:
image: stevobengtson/vt-phoenix-docker
command: /bin/bash /code/startup.sh
environment:
PORT: $PORT
links:
- db
- redis
volumes:
- .:/code
ports:
- "$PORT:$PORT"
depends_on:
- db
EOF
docker-compose up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment