mirror of
https://github.com/snibox/snibox.git
synced 2026-04-26 00:06:12 +03:00
[GH-ISSUE #36] Snibox-docker won't mount to host volumes. #33
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/snibox#33
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @gkoerk on GitHub (Nov 2, 2018).
Original GitHub issue: https://github.com/snibox/snibox/issues/36
It seems the frontend doesn't like the folders I am trying to bind mount for static_files. I've tried chmod on them and even chown, but I don't know the UID:GID this process expects to own a common static_files directory. Any ideas? Snibox will only start with the docker volumes, and won't start up at all when I try to bind mount to host volumes.
@piv-pav commented on GitHub (Nov 3, 2018):
Can you please provide your
Dockerfiletogether with yourdocker runcommand so we could understand what exactly you are mounting and where. Anyrailslogs either fromlogfolder ordocker logsshowing what is the errorrailsgenerates when you running application in container with binded volume would be also extremally helpful.@gkoerk commented on GitHub (Nov 3, 2018):
Original, failing configuration.
Dockerfile:
Here is the swarm-compatible
docker-compose.ymlused to attempt todocker stack deploy ...:Temporary Workaround
I believe the problem is that there is no VOLUME specified. I was only able to (partially) workaround by using this Dockerfile:
And the
docker-compose.yml:While this configuration allows me to bind to the host and thus retain my data, after initial deploy I must connect to the running docker container and execute
bin/rails db:migrate.@piv-pav commented on GitHub (Nov 3, 2018):
Thanks for the details. I have found few things which looks suspicious to me:
You are running 3 containers:
snibox/nginx-puma(a.k.a.frontend),gkoerk/snibox:latest(a.k.a.backend) andpostgres:10.1-alpine(a.k.a.database). I see thatbackendis configured as dependency forfrontend, but yourdatabaseisn't required by anything, sobackendcontainer won't be able to connect to thedatabase, as they won't be linked.I have no clue on what
frontendcontainer is intent to do here as I cannot see neitherDockerfileor any description of that image. In my understandingnginxshould only proxy HTTP requests to therails server, hence require only proper configuration file, but presumably nothing should be mounted in that container apart from the config.Rails should be serving static files by default, so I'm not sure why would you need to mount anything to
/app/public? What is the purpose for that?/app/publicfolder will contain all the JS files compiled by following command specified in yourDockerfile.In my case
/app/publicis 4.8Mb, so once you bind empty partition to/app/public,railswill start throwing errors as it cannot find required files to serve static pages (which is enabled).If you want to use PostgreSQL database you need to link it to the
backendcontainer in your composer configuration.And I believe that you don't need to mount any static files to your
sniboxcontainer as snibox isn't actually saving any data during its work apart from the database. Can you please elaborate on why you need to store static files outside the container?The workaround you mentioned is a
Dockerfileinitially created by me to runsniboxwithsqlite3database. Your modifications are creatingsqlite3database inside the container, so when you bind empty volume to/app/db/databasedocker will replace folder with existing database with empty one so you need to rundocker exec -ti <container> rails db:migratein order to create new database file. Once created you won't need to rundb:migrationanymore.However if you require automatic database createtion you could replace default
CMDcontainer parameter with something simillar to yourbackend.commandparameter:So you won't need to create database when running container.
@gkoerk commented on GitHub (Nov 3, 2018):
That docker-compose is also from you. It's linked from the docker instructions and is located here:
https://github.com/snibox/snibox-docker/blob/master/docker-compose.yml
@gkoerk commented on GitHub (Nov 3, 2018):
By the way - this is a great piece of software. Thanks for your work on it!!
@gkoerk commented on GitHub (Nov 3, 2018):
By the way,
This is not the case. In fact, linking containers is deprecated in docker-compose version 3 (and not recommended in version 2 anymore). Containers in the same stack share a namespace - they can communicate with one another by service name if on the same overlay network (even to ports that are exposed in the image but not mapped in the docker-compose). That is how docker recommends you now link containers.
Actually, the
depends_onis supported in a traditionaldocker-compose up -d, but not when used viadocker stack deploy <stack-name> -c docker-compose.yml(swarm mode). It really doesn't do much even in traditional compose mode. It doesn't ensure a service is healthy, just that it has been started. There is no supported way currently in any version of docker to explicitly control either startup order or how long a given service waits after another to start.Ultimately I need either a pre-built docker image which initiates the DB if it doesn't exist on first start, or to create my own as you've suggested. I presume the `it's not a problem when restarting the stack. How do you initially create and persist your DB data when rebooting the server?
I suppose sqlite3 is fine for now since this will be be used at first by only 1-3 people. But I really want to get a docker stack that can run both snibox and postgresql in one
docker-compose.ymlfor Docker Swarm. Now that I know nothing needs to be bind mounted, I'll stop trying! That may be the solution to the whole problem.@piv-pav commented on GitHub (Nov 3, 2018):
Hm, first of all, please note that I'm not a developer of the snibox, so have no idea on how this composer file should work at all. However the second
Dockerfileyou mention is the one I'm using to host my own instance of sniboxThat depends on the network type. With
ovelaynetwork andswarmI believe you right.sqlite3database is basically the file. Once being created it binds to the container and everything works fine. Doesn't matter if you restart your container as it stores on host storage. Basically I was keen to remove an extra layer with PG host.Currently you cannot register more than 1 user in single snibox installation, that was basically why I make an image with
sqlite3. If you want to host 3 different databases from different snibox installations in the same place then PostgreSQL makes sense.That of course depends on requirements but in my understanding you only need to create snibox container and postgres container to make snibox works. Nginx will be only required if you need SSL terminaton or some specific proxy configuration. Snibox itself doesn't require anything to be mounted to it, however PostgreSQL database files should be stored outside the container unless you want to loose all the data between container reboots\relocations.
Try to completely remove
frontendfrom your compose file, frombackendservice removevolumes, add port exposure80:3000and check if that would work.All in all I believe that your problem is more docker related rather than snibox, so we probably need to move our discussion to where its proper.
@piv-pav commented on GitHub (Nov 3, 2018):
I was able to run
sniboxwithpostgresqlusing following configuration:docker-compose.yml
Dockerfile for snibox
I also added
sleep 10to the sniboxCMDso snibox will give enough time forpostgresto start before doingrails db:migrate. That's rather a dirty hack and probably should be wrapped into proper startup script, however it works.@gkoerk commented on GitHub (Nov 11, 2018):
I get the following error when building the image on two different servers. Any chance you have the image you were able to generate on Docker Hub? :-)
@piv-pav commented on GitHub (Nov 12, 2018):
I also see those warning messages, but because they are not errors you can ignore them. Snibox is working fine after that.
@gkoerk commented on GitHub (Nov 12, 2018):
Oh - in that case something is still wrong. I get the following:
@piv-pav commented on GitHub (Dec 11, 2018):
I've updated the snibox-sqlite image in order to add automatic DB creation, so you can use it instead.