DEV Community

Cover image for Running in a container Part 2
Chuck Ha
Chuck Ha

Posted on

Running in a container Part 2

In my last post I covered building a docker image, but it was so rushed I won't even link it here.

This article aims to improve on that mess of a Dockerfile.

The commit can be found on my fork of the repo.

In order to get this version of running locally follow these steps (no cloning necessary):

# Setup a data directory for postgres
mkdir data

# Create the network that is shared between containers
docker network create devto

# Run the database
docker run --rm --network devto --name db -e POSTGRES_PASSWORD=devto -e POSTGRES_USER=devto -e POSTGRES_DB=PracticalDeveloper_development -v $(PWD)/data:/var/lib/postgresql/data postgres:10

and then in another terminal follow these steps for the application server:

# Setup the database and ensure dependencies are met
docker run --rm -it --network devto -e CONNECT_TIMEOUT=30 -e DATABASE_URL=postgresql://devto:devto@db:5432/PracticalDeveloper_development chuckdha/ bin/setup

# Run the webserver
docker run --rm -it --network devto -p 3000:3000 -e CONNECT_TIMEOUT=30 -e DATABASE_URL=postgresql://devto:devto@db:5432/PracticalDeveloper_development chuckdha/ bin/rails s

Then visit http://localhost:3000 in a web browser.

Let me know what you think!

Discussion (3)

rhymes profile image

Hi Chuck, maybe you want to contribute to or keep an eye on this pull request about adding Docker support to

chuck_ha profile image
Chuck Ha Author

I'm not 100% convinced should be run in a container to tell you the truth. It really depends on what the devs want but I'll put in my two cents. Thanks for the encouragement!

rhymes profile image

Sure, but it could lower adoption and contribution if people can have that option. I'm not much of a Docker user myself...