S
S
shell_guy2021-12-01 14:39:53
Docker
shell_guy, 2021-12-01 14:39:53

How to transfer data from one docker container to another?

There are 2 docker containers:
1) a self-assembly container (a python script-parser is launched by cron)
2) DB

How to write data from a docker container (1) to a docker container (2)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Karabanov, 2021-12-01
@karabanov

Combine containers into one virtual network. Of course, you can manually configure everything, but this is not advisable.
Use docker-compose.
docker-compose.yml might look like this:

version: "3.2"
services:
  my_db:
    image: mysql:8.0.26
    restart: always
    container_name: mysql8
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: superpassword
    ports:
    working_dir: /var/lib/mysql
    volumes:
      - "./mysql:/var/lib/mysql:rw"

  app:
    build: ./app/
    command: >
          python3 app.py
    depends_on:
      - my_db

You can access the data meringue from the application by the name of the service, in this case my_db

P
pandadevelop, 2021-12-01
@pandadevelop

The database from the second container should be available for external connections
if you have mysql, then you can connect to mysql in python, for example, through the root user on localhost:3306 and write the parsed data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question