【发布时间】:2020-10-02 00:19:50
【问题描述】:
我正在努力连接两个容器服务。具体来说,我想使用在一个容器中运行的 Redis 服务器 (https://hub.docker.com/_/redis/):docker run -d --name my_redis_server redis,自定义映像运行如下:docker run -p 8888:8888 --mount type=bind,source=<my_folder>,target=/data/ my_container 使用以下 Dockerfile 和 docker-compose.yml 构建:
Dockerfile
FROM ubuntu
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
# Updates and tools
RUN apt-get update && \
apt-get install -y gcc make apt-transport-https ca-certificates build-essential git redis-server
RUN apt-get install -y wget && rm -rf /var/lib/apt/lists/*
RUN wget \
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& mkdir /root/.conda \
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
&& rm -f Miniconda3-latest-Linux-x86_64.sh
RUN conda --version
# Create conda environment
RUN conda create python=3.6 --name my_env
# Run in a new shell
RUN /bin/bash -c "activate my_env"
RUN <Install some packages>
RUN conda install -c conda-forge jupyterlab -y
RUN conda install -c anaconda redis
# The code to run when the container is started:
# Entrypoint
WORKDIR /data/
ENTRYPOINT ["jupyter", "notebook", "--ip=0.0.0.0", "--no-browser", "--allow-root"]
docker-compose.yml
version: '2.3'
services:
my_container:
container_name: my_container_env
build: ./
restart: always
ports:
- '8888:8888'
根据我的理解,我应该能够使用内部网桥 IP(即 172.17.0.X)或 docker DNS 名称(即 my_redis_server)从 my_container(特别是 jupyter)连接到 my_redis_server ) 在这两种情况下都使用标准 Redis 映像端口 6379。
不幸的是,这对我不起作用...我错过了什么?
谢谢大家!
系统:Windows 10 - Docker 2.3.0.2
补充说明:
我确实尝试(作为解决方法)改变方法并通过将 my_container 运行为:docker run -p 8888:8888 -p 6379:6379 --mount type=bind,source=<my_folder>,target=/data/ my_container 并从容器内的 jupyter 连接到本地主机 Redis 服务器(编译的 WIN 版本)连接本地主机为127.0.0.1:6379,这也不起作用。
【问题讨论】:
标签: python docker redis docker-compose dockerfile