Docker化现有的应用和数据库

时间:2017-07-31 15:30:18

标签: django postgresql docker docker-compose dockerfile

我正在尝试Dockerize已经创建的应用程序(包括数据库)。

我已经准备好了正确的文件:

  • 搬运工-compose.yml
  • dockerfile
  • requirements.txt

我在使用数据库部分时遇到问题 - 如何配置docker-compose.yml文件以指向已创建的数据库?

这就是为什么我问 - 我对Docker的理解 - 是你创建你的基础应用程序 - 然后“Dockerize”它或将它打包成一个你可以分发的图像。我是初学者 - 所以这可能就是我不理解的原因。

这是我目前的docker-compose.yml:

    version: '2'

services:
  db:
    image: postgres:9.6
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=qwerty
      - POSTGRES_DB=ar_db
    ports: 
      - "5433:5433"
  web:
    build: .
    command: python2.7 manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

和dockerfile:

############################################################
# Dockerfile to run a Django-based web application
# Based on an Ubuntu Image
############################################################

# Set the base image to use to Ubuntu
FROM debian:8.8

# Set the file maintainer (your name - the file's author)
MAINTAINER HeatherJ


# Update the default application repository sources list
RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y python python-pip libpq-dev python-dev



#install git
RUN apt-get update && apt-get install -y --no-install-recommends \
     git&& rm -rf /var/lib/apt/lists/*


# Set env variables used in this Dockerfile (add a unique prefix, such as DOCKYARD)
# Local directory with project source
ENV DOCKYARD_SRC=EPIC_AR
# Directory in container for all project files
ENV DOCKYARD_SRVHOME=/EPIC_AR
# Directory in container for project source files
ENV DOCKYARD_SRVPROJ=/home/epic/EPIC_AR/EPIC_AR

# Create application subdirectories
WORKDIR $DOCKYARD_SRVHOME
RUN mkdir media static logs
VOLUME ["$DOCKYARD_SRVHOME/media/", "$DOCKYARD_SRVHOME/logs/"]

# Copy application source code to SRCDIR
COPY $DOCKYARD_SRC $DOCKYARD_SRVPROJ

# Install Python dependencies

RUN pip install -r $DOCKYARD_SRVPROJ/requirements.txt



# Copy entrypoint script into the image
WORKDIR $DOCKYARD_SRVPROJ
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]

0 个答案:

没有答案