Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dockerfile, docker-compose config #30

Merged
merged 9 commits into from
Apr 27, 2021

Conversation

mikeyavorsky
Copy link
Collaborator

@mikeyavorsky mikeyavorsky commented Apr 21, 2021

Your .env file should include (along with any other required vars):

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=police_data
POSTGRES_HOST=db
  • db initialization script is ./init-user-db.sh, may need to be siloed / organized better
  • exposes port 5000 of the api, port 5432 for postgres db by default
  • takes POSTGRES_USER POSTGRES_PASSWORD and POSTGRES_DB from .env instead of docker-compose

build and run with docker-compose build; docker-compose up -d; docker-compose logs -f app

@mikeyavorsky mikeyavorsky changed the title Docker Add Dockerfile, docker-compose config Apr 21, 2021
POSTGRES_PASSWORD: postgres
POSTGRES_DB: police_data
volumes:
- ./init-user-db.sh:/docker-entrypoint-initdb.d/init-user-db.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use this as the volume - postgres:/var/lib/postgresql/data

with this at the end of the file:

volumes:
  postgres: {}

and I'd also connect this service to the to the dotenv file with:

    env_file:
      - ".env"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added both

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry it wasn't clear, also replace

    volumes:
      - ./init-user-db.sh:/docker-entrypoint-initdb.d/init-user-db.sh

with this:

    volumes:
      - postgres:/var/lib/postgresql/data

and then delete the init-user-db.sh file.

This appears to be a more standard way to dockerize Postgres databases that helps to persist data across migrations and deployments.

@dwreeves
Copy link
Contributor

One note about how the postgres service is defined, but otherwise LGTM

Stampeder525
Stampeder525 previously approved these changes Apr 21, 2021
Copy link
Contributor

@Stampeder525 Stampeder525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the first time in world history I can open the site

ryanmahan
ryanmahan previously approved these changes Apr 21, 2021
Copy link
Collaborator

@ryanmahan ryanmahan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked for me too

@dwreeves
Copy link
Contributor

One more comment regarding the Postgres service. Once we've resolved that, I'll give a LGTM.

@DMalone87 DMalone87 merged commit a2aa787 into codeforboston:main Apr 27, 2021
@mikeyavorsky mikeyavorsky deleted the docker branch April 28, 2021 00:19
@mikeyavorsky
Copy link
Collaborator Author

One more comment regarding the Postgres service. Once we've resolved that, I'll give a LGTM.

@dwreeves According to the Postgres Docker image documentation, the init script and db volume can coexist:
Warning: scripts in /docker-entrypoint-initdb.d are only run if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup.
See the initialization scripts section.

@DMalone87 DMalone87 linked an issue Apr 28, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Easy testing and development setup using docker compose
6 participants