D
D
domanskiy2021-02-13 01:18:03
Docker
domanskiy, 2021-02-13 01:18:03

How to connect a new container with existing ones in docker?

I have 3 containers running

abc4a396878a   dpage/pgadmin4   "/entrypoint.sh"         4 weeks ago   Up 41 hours   443/tcp, 0.0.0.0:5555->80/tcp   pgAdmin_cont
9063ca5b49af   app_app          "python main.py"         4 weeks ago   Up 41 hours   0.0.0.0:5050->5050/tcp          app_flask_api
476cc4dffe86   postgres:13      "docker-entrypoint.s…"   4 weeks ago   Up 41 hours   0.0.0.0:6532->5432/tcp          postgres_cont

I need to create a build and another container.
Dockerfile
FROM python:3.8

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# set work directory
RUN mkdir /app
WORKDIR /app
COPY . /app

ENV FASTAPI_ENV = "app"
# install dependencies

RUN pip install --upgrade pip
RUN pip install -r req.txt
RUN pip install -r req.txt

VOLUME .:/app

EXPOSE 8000
CMD ["python", "main.py"] 
# порт и пр прописаны в конфигах main.py


docker-compose.yml
version: '3.8'
services:
  app_fastapi:
    container_name: "app_fastapi"
    build:
      context: ./
      dockerfile: Dockerfile
    volumes:
      - .:/app
    ports:
      - 8000:8000
    entrypoint: ["python", "main.py"]
    restart: unless-stopped


The image is created. The container is created and launched. BUT! no access from outside. The new container does not have access to the container with the Postgre database
How to fix this?
Write new docker-compose.yml to all four containers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2021-02-13
@domanskiy

And docker execthere docker runis an option, --linkrespectively, in the composition there islinks:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question