代码之家  ›  专栏  ›  技术社区  ›  Scott Skiles

如何在远程服务器上以Docker compose的方式运行Docker容器?

  •  0
  • Scott Skiles  · 技术社区  · 6 年前

    日间;夜间: 获取错误 /docker-entrypoint.sh: line 10: exec: nginx: cannot execute: Is a directory 跑步 docker run username/srdc_prod:2020.07.26 什么时候 docker-compose up

    我有一个docker容器,我已经推到DockerHub了。我可以在本地运行docker compose。我在我的远程服务器上下载了这个,现在我正在尝试使用 docker运行用户名/srdc_生产日期:2020.07.26 .

    /码头工人-入口点.sh:line 10:exec:nginx:cannot execute:是一个目录 . 执行 码头工人准备 码头工人准备 因为 docker-compose.yaml 文件远程不存在。我意识到我可以尝试远程克隆GitHub repo然后运行 码头工人准备 但是,这将破坏将容器推送到DockerHub并最终设置CI/CD的目的。

    this question docker ps --no-trunc docker-entrypoint.sh 无法远程执行的文件。我是不是做错了,需要重构Dockerfile才能在远程服务器上运行?

    远程服务器上的映像

    username@ubuntu-512mb-name:~$ docker image ls
    WARNING: Error loading config file: /home/username/.docker/config.json: stat /home/username/.docker/config.json: permission denied
    REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
    username/srdc_prod        2020.07.26          af62927882ee        5 days ago          504MB
    

      1 #!/bin/bash
      2
      3 echo "Collect static files"
      4 python manage.py collectstatic --noinput
      5
      6 echo "Apply database migrations"
      7 python manage.py migrate --noinput
      8
      9 echo "Starting daphne server"
     10 exec "$@" # offending line
    

    Dockerfile文件

    FROM python:3-alpine
    
    # set env vars
    ENV PYTHONDONTWRITEBYTECODE 1
    ENV PYTHONUNBUFFERED 1
    
    RUN mkdir /app
    
    RUN apk update && apk add --no-cache postgresql-dev gcc libffi-dev musl-dev build-base python3-dev bash
    
    COPY requirements.txt /app/requirements.txt
    RUN pip install --upgrade pip && pip install --no-cache-dir -r /app/requirements.txt
    
    COPY test-requirements.txt /app/test-requirements.txt
    RUN pip install --upgrade pip && pip install --no-cache-dir -r /app/test-requirements.txt
    
    COPY . /app
    # set working directory
    WORKDIR /app
    
    RUN mkdir -p /var/www/srdc/static/
    RUN chmod 755 /var/www/srdc/static/
    
    EXPOSE 8000
    
    ENV DJANGO_SETTINGS_MODULE=srdc.settings
    
    CMD ["nginx", "-g", "daemon off;"]
    
    ADD docker-entrypoint.sh /docker-entrypoint.sh
    RUN chmod a+x /docker-entrypoint.sh
    ENTRYPOINT ["/docker-entrypoint.sh"]
    

    码头工人-合成.yml

    version: '3'
    
    services:
      django_web:
        build: .
        command: bash -c "daphne -b 0.0.0.0 -p 8000 srdc.asgi:application"
        expose:
           - 8000
        image: srdc:v0
        container_name: srdc_django_web
        volumes:
          - .:/app
          - static_volume:/var/www/srdc/static/
        depends_on:
          - db
      nginx:
        build: ./nginx
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - static_volume:/var/www/srdc/static/
          - ./data/certbot/conf:/etc/letsencrypt
          - ./data/certbot/www:/var/www/certbot
        depends_on:
          - django_web
      db:
        image: postgres
        container_name: "my_postgres"
        ports:
          - "54320:5432"
        volumes:                                                                                                                                                                                     - my_dbdata:/var/lib/postgresql/data
    volumes:                                                                                                                                                                                       my_dbdata:
        static_volume:                                                                                                                                                                             media_volume:
    
    0 回复  |  直到 6 年前
        1
  •  1
  •   benbotto    6 年前

    您看到的错误是准确的: nginx docker-compose.yml 马尼菲特,有一个 nginx公司 根目录中用作

      nginx:
        build: ./nginx # Here's the evidence for the nginx folder.
        ports:
    

    当你建立 django_web 镜像,将整个上下文目录复制到 /app ,其中包括

    COPY . /app
    # set working directory
    WORKDIR /app
    

    这个 CMD 为了你 username/srdc_prod nginx -g daemon off; ,你的 docker-entrypoint.sh 执行。失败的原因是 nginx公司

    基于你的 码头工人-合成.yml 你真正想要的是 daphne -b 0.0.0.0 -p 8000 srdc.asgi:application 或者类似的事情,但不是 nginx公司

    一些超出问题范围的建议。

    1. docker run 命令。
    2. 更好的是,在蜂群模式下使用Docker。你可以这样重复使用你的清单文件,尽管你需要删除一些不推荐的东西( depends_on