通过docker-compose在Pycharm上运行Python控制台


69

我在通过docker-compose使用远程python解释器运行pycharm时遇到一些问题。当我按下运行按钮时,除Python控制台外,其他所有功能都运行良好,仅显示以下消息:

“错误:无法从docker-compose输出中找到服务“ web”的容器名称”

我真的不明白,如果我docker-compose.yml提供web服务,为什么它会让我继续显示。

有什么帮助吗?

编辑:

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

Docker文件

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

这是python映像Dockerfile,Web Dockerfile只是从该映像中声明并将源文件夹复制到容器中。


不...坦白地说,我几个月前就放弃了。我正在通过docker运行jupyter实例,以在我的项目上使用更灵活的shell。
维克多·吉马良斯·纳内斯(VictorGuimarãesNunes)

2
问题已解决但已退回
crizCraig

1
可能还需要在此处进行记录:youtrack.jetbrains.com/issue/PY-18748这是自7月19日起已修复的票证,只需要发布即可。-等待中的游戏..
哈维尔·巴齐

1
这可能是一个长镜头,但是您是否尝试过container_name在Web服务上设置属性?
泰隆·威尔逊

Answers:



0

通过命令行安装所需的库并从PATH运行python解释器就足够了。

您也可以参考JetBrains手册,了解它们如何为其IDE的解释器配置。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.