M
M
Max Payne2019-06-03 12:47:04
Python
Max Payne, 2019-06-03 12:47:04

How to effectively use Docker + Docker-compose in development?

I have never worked closely with docker, and now there is a need for this, since in the future the application will need to be deployed on a remote server.
I threw a small docker-compose based on knowledge from the information I read

docker-compose.yaml
version: '3'

services:
  parser:
    build: ./parser
    restart: always
    container_name: JaScrapy01
    depends_on:
      - postgres
      - redis
    volumes:
      - ./parser:/JaScrapy
    networks:
      - net
    env_file:
      - .env
  postgres:
    image: postgres:11.3-alpine
    restart: always
    container_name: postgres01
    networks:
      - net
    volumes:
      - ./postgres/data:/var/lib/postgresql/data
    env_file:
      - .env
  redis:
    image: redis:5.0.5-alpine
    restart: always
    container_name: redis01
    networks:
      - net
    volumes:
      - ./redis/data:/data
    env_file:
      - .env

networks:
  net:


But it turns out to be very inconvenient! Yes, the containers themselves rise with postgresql and redis, this is convenient, but you cannot connect to them from the outside (due to the use of networks, and you need to guess how to open the network yourself), let's say to view information through the GUI. When making any changes to the main application, one can only hope that they will someday appear in the container. You can delete the container with the application five times, then delete the image ten times - no changes will get anywhere. In this case, it is impossible to use a virtual environment on the local machine, launching the application through it, because the database network is local somewhere. Pycharm can use an interpreter running inside a container - but it connected when it was a long time ago and only PyCharm's java errors are thrown after that.
Actually, the question is how to work effectively and conveniently with this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2019-06-03
@YardalGedal

but you can’t connect to them from the outside (due to the use of networks, and how to open a network -
you need to guess yourself)

And through the directives ports - aren't the necessary ports thrown out of the containers out?
When making any changes to the main application
, one can only hope that they will someday appear in the container

If you make changes to a project that is mapped via volume, then the container sees them immediately.
Whether your application can see that local files have changed and apply them is another matter.
But even if it does not know how, there is no problem restarting the desired container after making any changes.
You can delete the container with the application five times, then delete the image ten times,
no changes will get anywhere.

I don’t know how you built it - but I’ll give you examples with python projects.
In Python, a folder with a virtual environment is created, where all the necessary libraries for work are installed. This folder is mapped together with the project into a container. This uses the python container from the standard image for all projects, and the virtual environment from the mapped directory. There is no need to install anything additional in containers. Therefore, what you are trying to do with the images is not clear ...
In this case, it is impossible to use a virtual environment on the local machine, launching the application through it,
because the database network is local somewhere.

Well, here you decide - use docker for this, or a virtual environment on your machine.
If you want to use both at the same time, forward the ports.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question