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

Older install of IN4 via Docker Compose is stuck on 4.5.18 and can't be upgraded to 4.5.19 #194

Closed
andrewhaji opened this issue Aug 23, 2020 · 11 comments
Labels
need feedback Needs feedback from creator

Comments

@andrewhaji
Copy link

Hi all,

I've been running IN4, self-hosted, via Docker, for months now. Works great. I followed the (older) install instructions from this wiki precisely. Had a bit of trouble when the invoiceninja:latest branch jumped up to 5.0, but I managed to get back to 4.x by updating the docker-compose file to show invoiceninja:4.5.18.

Now, I see 4.5.19 is available, but only in an alpine variety. I tried updating my docker-compose file to refer to invoiceninja:alpine-4 instead of invoiceninja:4.5.18, but when I try to bring it up the cron container crashes instantly and the app container restarts continuously.

I've noticed that the dockerfiles and sample docker-compose files on this repository have been completely rewritten in the last few months. Is there any way to transition my older docker-compose install to the current one, allowing me to move up to 4.5.19 (and eventually migrate to 5.0)?

Many thanks for the help.

@codedge
Copy link
Contributor

codedge commented Aug 23, 2020

To help you I need the errors you face. How to get the errors you can see on the Debuggung and FAQ in the wiki.

Can you also paste your full docker-compose.yml please

I am pretty sure we get you to the latest 4.x version - after that, we can discuss about moving to 5.

@codedge codedge added the need feedback Needs feedback from creator label Aug 23, 2020
@andrewhaji
Copy link
Author

andrewhaji commented Aug 23, 2020

Here is my current (100% working) docker-compose, before I've made any changes to it:

version: '3.6'

volumes:
  db:
  storage:
  logo:
  public:

# uncomment if you want to use external network (example network: "web")
#networks:
#  web:
#    external: true

services:
  db:
    image: mysql:5
    env_file: .env
    restart: always
    volumes:
      - db:/var/lib/mysql
    networks:
      - default

  app:
    image: invoiceninja/invoiceninja:4.5.18
    env_file: .env
    restart: always
    depends_on:
      - db
    volumes:
      -  storage:/var/www/app/storage
      -  logo:/var/www/app/public/logo
      -  public:/var/www/app/public
    networks: 
      - default  

  web:
    image: nginx:1
    restart: always
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      -  storage:/var/www/app/storage
      -  logo:/var/www/app/public/logo
      -  public:/var/www/app/public
    expose: # Expose ports without publishing them to the host machine - they’ll only be accessible to linked services.
      - "80"
    depends_on:
      - app
    ports: # Delete if you want to use reverse proxy
      - 8000:80
    networks:
#      - web        # uncomment if you want to use  external network (reverse proxy for example)
      - default

  cron:
    image: invoiceninja/invoiceninja:4.5.18
    env_file: .env
    restart: always
    depends_on:
      - web
    volumes:
      -  storage:/var/www/app/storage
      -  logo:/var/www/app/public/logo
      -  public:/var/www/app/public
    entrypoint: |
      bash -c 'bash -s <<EOF
      trap "break;exit" SIGHUP SIGINT SIGTERM
      sleep 300s
      while /bin/true; do
        ./artisan ninja:send-invoices
        ./artisan ninja:send-reminders
        sleep 1d
      done
      EOF'
    networks:
      - default

I changed both references to invoiceninja/invoiceninja:4.5.18 to invoiceninja/invoiceninja:alpine-4 and ran docker-compose up -d again. Immediately I get the following error regarding the "cron" container:

Creating invoiceninja_cron_1 ... error

ERROR: for invoiceninja_cron_1  Cannot start service cron: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown

ERROR: for cron  Cannot start service cron: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown

When I look at the current (updated) docker-compose file from this wiki, it shows the "cron" container uses /bin/sh as an entrypoint instead of bash - maybe I just need to change that in my docker-compose file?

Running docker ps the invoiceninja_app_1 container shows Restarting (1) 14 seconds ago

When I run docker-compose logs -f I get a ton of errors similar to this:

app_1   | cp: can't preserve times of '/var/www/app/public/images/credit_cards': Operation not permitted
app_1   | cp: can't preserve ownership of '/var/www/app/public/images/credit_cards': Operation not permitted
app_1   | cp: can't preserve permissions of '/var/www/app/public/images/credit_cards': Operation not permitted
app_1   | cp: can't create '/var/www/app/public/images/about2@2x.jpg': File exists
app_1   | cp: can't create '/var/www/app/public/images/PersonalizeInvoiceColor.png': File exists
app_1   | cp: can't create '/var/www/app/public/images/AlertsWhenInvoicesViewed.png': File exists
app_1   | cp: can't create '/var/www/app/public/images/shalomstark.jpg': File exists
app_1   | cp: can't create '/var/www/app/public/images/report_logo3.jpg': File exists
app_1   | cp: can't create '/var/www/app/public/images/icon-secure-pay.png': File exists
app_1   | cp: can't create '/var/www/app/public/images/social.jpg': File exists
app_1   | cp: can't create '/var/www/app/public/images/hero-bg-plans.jpg': File exists

Perhaps an issue with file permissions? The volumes are docker named volumes so I don't manage the permissions myself. If I go to /var/lib/docker/volumes/invoiceninja_public/_data/ on my host, all the files and folders in that volume are owned by www-data:www-data.

Thank you so much for the help.

EDIT: I spun up a fresh IN4 instance on my machine and checked the invoiceninja_public volume to see what the permissions were set to. The files and folders were all set to UID 1000 and GID 82, so it's not the same as what the old non-alpine image set it to (www-data:www-data). So my guess is that I need to reset the permissions on my existing volume to 1000:82, but how do I safely do that?

@andrewhaji
Copy link
Author

I've been looking through some of the closed issues on this repository and I found one that seems almost identical to mine: #173

I will update the entrypoint in my docker-compose.yml to point to /bin/sh instead of bash. Hopefully that will fix the cron issue.

As for the file permissions issue, this wiki entry confirms that I need to reset my permissions to 1000:82. But how do I do that on a docker named volume? Do I just do this?

chown -R 1000:82 /var/lib/docker/volumes/invoiceninja_public/_data /var/lib/docker/volumes/invoiceninja_storage/_data

I've always read that you shouldn't mess with docker named volumes from the host, but you should mount them in a container and work with them that way. I'm not sure how I would go about doing this, though.

@codedge
Copy link
Contributor

codedge commented Aug 24, 2020

Hey @andrewhaji

sorry for the waiting.

Cron

Due to the usage of alpine as base image there is no bash existend anymore. So yes, the cron script needs to target sh. A current version can just be copy&pasted from the docker-compose.yml.

Volumes & perms

I think you can log into the container, e. g. docker-compose exec app sh, then navigate to the proper directory with cd /var/www/app and then apply the correct owner and group with chown -R 1000:82 public

Don't do this chown -R 1000:82 /var/lib/docker/volumes/invoiceninja_public/_data /var/lib/docker/volumes/invoiceninja_storage/_data as this changes the owner for the volumes on your host system which is not what you want.

@andrewhaji
Copy link
Author

Thanks for the reply!

I tried to do what you suggested -- running docker-compose exec app sh to get a shell in the app container. However, because the app container is constantly restarting, I get this:

Error response from daemon: Container 2434f6d1935f6b34d6105e6f8c3d9e087535d7da93ea807c3a9fcc008228ab8f is restarting, wait until the container is running

Any thoughts? Thank you.

@codedge
Copy link
Contributor

codedge commented Aug 24, 2020

Yes, you can also use the web or cron container. Both have the public folder mounted

@andrewhaji
Copy link
Author

Okay, so I took a snapshot of my VM just in case I totally broke something, and I tried running (from my host):

chown -R 1000:82 \
  /var/lib/docker/volumes/invoiceninja_public/_data \
  /var/lib/docker/volumes/invoiceninja_storage/_data \
  /var/lib/docker/volumes/invoiceninja_logo/_data

Then did docker-compose up -d and checked the log files. It works!

I don't know if there will be any negative side-effects to having changed the permissions from the host rather than from inside the container, but for now everything seems to be working.

Many thanks for helping me figure this out!

Do you think it would be useful to add a page on the wiki regarding this? I feel like there must be a lot of people in a similar situation - having to migrate from the older non-alpine docker builds to the alpine builds.

@andrewhaji
Copy link
Author

Yes, you can also use the web or cron container. Both have the public folder mounted

Oops, sorry, didn't see this until now. Thanks for this suggestion.

@codedge
Copy link
Contributor

codedge commented Aug 24, 2020

I will add a wiki page for that. Might be good starting point. Information about cronjobs can be found here.

Feel free to close the issue.

@andrewhaji
Copy link
Author

Thanks again for your help, and thank you for your continued work on this fantastic piece of software.

@andrewhaji
Copy link
Author

In case anyone stumbles upon this issue, I've encountered this same problem when upgrading my IN4 setup from 4.5.22 to 4.5.26 (or higher). It looks like the permissions now have to be set to 1500:82 instead of 1000:82. Not sure why the change was made but if your IN4 app container keeps restarting, try resetting the permissions to 1500:82 using the method I outlined above, and it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need feedback Needs feedback from creator
Projects
None yet
Development

No branches or pull requests

2 participants