How to use sqlite3 with Docker Compose

Asked

Viewed 1,759 times

0

Since sqlite3 banks are only files;
And containers, by their own logic of scalability are created and excluded according to need;
What is the best way to work with both partners?
You see, I’m trying to avoid creating a new image or volume for this bank, but honestly I’m open to possibilities.
I asked a related question here, but with another focus.

I also know that there may be a thousand alternatives to the bank chosen, but as new in the area, I have familiarity and confidence in sqlite3 and would like solutions to this.

----- Edited -----

I have in my app folder, a subfolder called volume.
And I’d like to access the folder /var/www/volumet host.
My Dockerfile after the answer:

FROM python:3-alpine

ADD ./var/www/volumet /app
WORKDIR /app

RUN apk add --update alpine-sdk make gcc python3-dev python-dev libxslt-dev libc-dev openssl-dev libffi-dev
RUN pip install --trusted-host pypi.python.org -r requirements.txt

EXPOSE 5050

ENV NAME Ibuprofenovar

CMD ["python", "app.py"]


My Docker-Compose.yml after reply:

version: "3"
services:
  web:
    build: .
    volumes:
      - /var/www/volumet:/volume
    deploy:
      replicas: 3
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "4000:5050"

1 answer

0

You need to set a volume in your Docker-Compose file that points to where your sqlite file is located,

Docker-Compose.yml version: "3"

services:
  app:
    restart: on-failure
    build: .
    container_name: myapp
    volumes: 
      - ./code:/app
    ports:
      - "5000:5000"

dockerfile

FROM python:3.6
ADD ./code /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD python run.py

With the volume set, the files from the code folder will be mirrored into the app folder inside the container. Maybe this solves your problem.

Edit

https://github.com/LuisMSoares/sqlite-docker-compose

  • Good morning, @Luiseduardo. According to your answer, I edited my question, but still unsuccessful

  • You built it after the Docker-Compose change?

  • Yes, but it hangs in the ADD command and does not finish the build. I tried to change the /var/www/volumet for ../../../../www/volumet but from the path Forbidden. Maybe I’m ignoring Docker’s idea of using directories from inside the image directory, but I think if I use it that way, when updating my files with a git pull for example, it overwrites my database likewise.

  • suggested changes, with the volume created, you do not need the Copy, and also need the . after the ADD as in my dockerfile ADD . /code /app

  • Yeah, but this way, with . it uses my project path, right? There’s no way to access the host’s /var/www path? Otherwise, if it is impossible, I will close my question right here, accept and give as answered.

  • If your dockerfile and Compose is in an X folder and your code is in a Y folder, you need to put ADD. /Y /app, because it is the local path + the folder path q you want to create the volume, in this case the folder Y, only the files inside it will be mirrored inside the container. Now if you want to put everything, just put ADD . /app so all local data will be mirrored inside.

  • I managed to insert the bank already created in the containers, but I can’t change it, as if the path of my volume was not right.

  • In my code, I go to the folder /volume and I can make changes to it, but these changes don’t affect my host folder, only the one in the container

  • Here friend, this solves your problem. https://github.com/LuisMSoares/sqlite-docker-compose

  • I know I’m not supposed to keep saying things like thank you or whatever. But something came up here that became a priority, so when the time comes for new tests, I make a new position. I will probably delete this comment in the sequence. Thanks for the response and interest.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.