RUN apt-get update -qq && apt-get install -y nodejs npm postgresql-client
RUN npm install -g yarn
RUN gem update --system
# use a global path instead of vendor
# make 'docker logs' work
# copy the source
COPY . /app
RUN rm -f tmp/pids/server.pid
RUN bundle install
# build and start
Can you show the compose file and how you tried to access the app so we can compare the working and the non-working solutions?
Check your filewalls too in your network and on the Docker host like ufw which can restrict access to some Docker network. If you find any firewall on your machine you can temporarily turned them off to see if that helps.
I"ve updated. When running docker-compose we use a different .env and the port is 3001 instead of 80 and it works fine.
I’m on a mac and shouldn’t think I have any firewalls running. One thing to note when I hit the expected port number it says forbidden so I want to feel something is happening but the end result is I can’t access the app.
Yes, I tried ports 80, 3000, and 3001. I also tried using the -p instead of --published, not even sure what the published does but saw it somewhere. None of these solved the problem. I also can’t stop the process with a Ctrl-C afterward. I have to run docker kill to stop it. I feel so close. The fact it works with docker-compose makes this very confusing for me. I guess docker-compose is doing something extra that I’m not doing.
docker run --env-file=.env.staging -p 3001:3000 my-app
Does your app depend on a /home/app folder? I don’t see you define that same bind mount when not using Compose?
Aside, why are you (re-)creating the app in the entrypoint.sh? That basically rebuilds the app whenever starting the container. I’d do that only once, when creating the image (that you’ll use later when starting it as a container.)
@rimelek and @avbentem thanks for the tips. I did update the docker-compose so the paths are consistent and I removed the extra create and now my entrypoint.sh looks like the following.
bin/rails server -b 0.0.0.0
So… I actually fixed the issue but realized a new one. I started the app with RAILS_ENV=development and it ran and I could hit the app on the expected port! However, when I set it back to RAILS_ENV=staging, it does not work. I’ve been testing staging all this time then I thought to try setting the environment to development and it works. Now I’m trying to understand why it won’t work when set to staging. Almost there. Ran without docker and app starts in staging environment but start with docker run and it doesn’t work when set to staging.