A
A
artloveyou2021-12-22 15:40:34
Python
artloveyou, 2021-12-22 15:40:34

How to create a container in docker so that files are taken from an external directory?

Explain in simple terms about creating a docker container.

I have already read a bunch of documentation and tutorials, I use docker itself and want to create my own container.
Here I have a code on a node and on a python, which versions are selected for this whole set so that everything starts up and the necessary dependencies are added. Question one: Python has additional modules installed, there is no package.json analogue, so, as I understand it, it is necessary to prescribe the installation of these modules manually, or what?

Then there is the code, which is unchanged, there are configs and a directory with changing files.

Here's how to create a container that will contain immutable code and work with configs and files from outside? At least a simple example.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-12-22
@artloveyou

Package.json analog - requirements.txt file for pip or analogs for other systems like pipenv.
We make a container in which we add our code, something like this:

ADD app /app
WORKDIR /app
RUN apt install python3-pip && pip install -r requirements.txt

Then, when starting the container, we pass it a directory with the necessary directories (in this case, configs and logs):
docker run -itd --name my_service -v `pwd`/config:/app/config:ro -v /var/log/my_project/my_service:/app/log my_awesome_image

Or via the volumes section in docker-compose.yml (it's more convenient than calling docker directly):
volumes:
    - ./config:/app/config:ro
    - /var/log/my_project/my_service:/app/log

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question