Run Python Console via docker-compose on Pycharm

PythonDockerDocker ComposePycharm

Python Problem Overview


I'm having some problems running pycharm with a remote python interpreter via docker-compose. Everything works just great except Python console when I press the run button it just shows the following message:

> "Error: Unable to locate container name for service "web" from > docker-compose output"

I really can't understand why it keeps me showing that if my docker-compose.yml provides a web service.

Any help?

EDIT:

docker-compose.yml

version: '2'

volumes:
  dados:
    driver: local
  media:
    driver: local
  static:
    driver: local

services:
  beat:
    build: Docker/beat
    depends_on: 
      - web
      - worker
    restart: always
    volumes:
      - ./src:/app/src
  db:
    build: Docker/postgres
    ports:
      - 5433:5432
    restart: always
    volumes:
      - dados:/var/lib/postgresql/data
  jupyter:
    build: Docker/jupyter
    command: jupyter notebook
    depends_on: 
      - web
    ports:
      - 8888:8888
    volumes:
      - ./src:/app/src
  python:
    build:
      context: Docker/python
      args:
        REQUIREMENTS_ENV: 'dev'
    image: helpdesk/python:3.6
  redis:
    image: redis:3.2.6
    ports:
      - 6379:6379
    restart: always
  web:
    build:
      context: .
      dockerfile: Docker/web/Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    depends_on:
      - python
      - db
    ports:
      - 8001:8000
    restart: always
    volumes:
      - ./src:/app/src
  worker:
    build: Docker/worker
    depends_on: 
      - web
      - redis
    restart: always
    volumes:
      - ./src:/app/src

Dockerfile

FROM python:3.6

# Set requirements environment
ARG REQUIREMENTS_ENV
ENV REQUIREMENTS_ENV ${REQUIREMENTS_ENV:-prod}

# Set PYTHONUNBUFFERED so the output is displayed in the Docker log
ENV PYTHONUNBUFFERED=1

# Install apt-transport-https
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y \
        apt-transport-https

# Configure yarn repo
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list

# Install APT dependencies
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y \
        locales \
        openssl \
        yarn

# Set locale
RUN locale-gen pt_BR.UTF-8 && \
    localedef -i pt_BR -c -f UTF-8 -A /usr/share/locale/locale.alias pt_BR.UTF-8

ENV LANG pt_BR.UTF-8
ENV LANGUAGE pt_BR.UTF-8
ENV LC_ALL pt_BR.UTF-8

# Copy requirements files to the container
RUN mkdir -p /tmp/requirements
COPY requirements/requirements-common.txt \
    requirements/requirements-$REQUIREMENTS_ENV.txt \
    /tmp/requirements/

# Install requirements
RUN pip install \
    -i http://root:test@pypi.defensoria.to.gov.br:4040/root/pypi/+simple/ \
    --trusted-host pypi.defensoria.to.gov.br \
    -r /tmp/requirements/requirements-$REQUIREMENTS_ENV.txt

# Remove requirements temp folder
RUN rm -rf /tmp/requirements

This is the python image Dockerfile, the web Dockerfile just declares from this image and copies the source folder to the container.

Python Solutions


Solution 1 - Python

I think that this is an dependency chain problem, web depends on python so, when the python container gets up, web one still not exists. That may cause the error.

Cheers

Solution 2 - Python

Installing required libraries via command line and running the python interpreter from the PATH should suffice.

You can also refer to the JetBrains manual, as to how they have configured for the interpreters of their IDEs.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVictor Guimarães NunesView Question on Stackoverflow
Solution 1 - PythonPablo MartinezView Answer on Stackoverflow
Solution 2 - Pythonuser9205630View Answer on Stackoverflow