epicweb-dev / epic-stack

This is a Full Stack app starter with the foundational things setup and configured for you to hit the ground running on your next EPIC idea.
https://www.epicweb.dev/epic-stack
MIT License
4.4k stars 364 forks source link

Add documentation to run app locally with Docker #662

Closed andreareginato closed 4 months ago

andreareginato commented 6 months ago

After a short conversation with @kentcdodds on Discord, I'm opening this issue in order to run the docker image locally. As Kent said, it may be worth removing LiteFS from the stack for this use case (doing that would allow you to avoid the consul service, which is the core issue I'm facing). Could be useful to add some docs on this.

Here I share my (failed) attempts.

# build the docker image
❯_ docker build . -t d4s --file other/Dockerfile
# run the docker image
❯_ docker run -p 3100:80 -it d4s

When I run the docker image I get the following error connected to consul.

config file read from /etc/litefs.yml
LiteFS v0.5.11, commit=63eab529dc3353e8d159e097ffc4caa7badb8cb3
level=INFO msg="no backup client configured, skipping"
level=INFO msg="Using Consul to determine primary"
level=INFO msg="initializing consul: key=epic-stack-litefs/ url= hostname=8053c4e40722 advertise-url=http://8053c4e40722.vm..internal:20202"
level=INFO msg="cannot fetch cluster ID from \"consul\" lease, retrying: Get \"http://127.0.0.1:8500/v1/kv/epic-stack-litefs/clusterid\": dial tcp 127.0.0.1:8500: connect: connection refused"
level=INFO msg="mount helper error: fusermount3: fuse device not found, try 'modprobe fuse' first"
ERROR: cannot init file system: cannot open file system: fusermount: exit status 1

I believe there is the need to install and configure consul, but here comes my lack of knowledge on the topic. What I did was to run Consul locally, which seems to work just fine.

# pull consul image
❯_ docker pull hashicorp/consul

# run consul container
❯_ docker run \
    -d \
    -p 8500:8500 \
    -p 8600:8600/udp \
    --name=badger \
    --privileged \
    hashicorp/consul agent -server -ui -node=server-1 -bootstrap-expect=1 -client=0.0.0.0

Then I tell the remix app container to access the host machine's localhost in order to connect to Consul, but still, I get similar errors. It seems I'm missing some important pieces due to my lack of Docker and dev-ops knowledge.

This makes me think that Kent idea, of removing litefs locally, could be the best way to go (to simplify things).

Thanks everyone

andreareginato commented 4 months ago

@kentcdodds @fredericrous do you have any hint on how to approach this issue? Happy to give some time, if I can be guided on where the changes should be made.

fredericrous commented 4 months ago

im not a litefs/consul expert but one idea to make litefs go away for your use case: you could create a multi stage docker build, install litefs in stage 2. and target stage 1 when you docker build for local dev. target stage 2 for CI. have a look at https://docs.docker.com/build/building/multi-stage/ there is also a good example of multi stage docker build on the pnpm documentation website https://pnpm.io/docker

rajeshg commented 4 months ago

This could be closed now. https://github.com/epicweb-dev/epic-stack/pull/741 addresses this.