gpt4 book ai didi

Docker 容器基于 OSX 而不是 Amazon Linux 构建

转载 作者:行者123 更新时间:2023-12-04 19:42:49 29 4
gpt4 key购买 nike

我的 Docker 容器在 OSX 上构建良好:

Docker version 17.12.0-ce, build c97c6d6  
docker-compose version 1.18.0, build 8dd22a9

但不在 Amazon Linux 上构建:
Docker version 17.12.0-ce, build 3dfb8343b139d6342acfd9975d7f1068b5b1c3d3  
docker-compose version 1.20.1, build 5d8c71b

完整的 Dockerfile:
# Specify base image
FROM andreptb/oracle-java:8-alpine

# Specify author / maintainer
MAINTAINER Douglas Duhaime <douglas.duhaime@gmail.com>

# Add source to a directory and use that directory
# NB: /app is a reserved directory in tomcat container
ENV APP_PATH="/lts-app"
RUN mkdir "$APP_PATH"
ADD . "$APP_PATH"
WORKDIR "$APP_PATH"

##
# Build BlackLab
##

RUN apk add --update --no-cache \
wget \
tar \
git

# Store the path to the maven home
ENV MAVEN_HOME="/usr/lib/maven"

# Add maven and java to the path
ENV PATH="$MAVEN_HOME/bin:$JAVA_HOME/bin:$PATH"

# Install Maven
RUN MAVEN_VERSION="3.3.9" && \
cd "/tmp" && \
wget "http://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz" -O - | tar xzf - && \
mv "/tmp/apache-maven-$MAVEN_VERSION" "$MAVEN_HOME" && \
ln -s "$MAVEN_HOME/bin/mvn" "/usr/bin/mvn" && \
rm -rf "/tmp/*"

# Get the BlackLab source
RUN git clone "git://github.com/INL/BlackLab.git"

# Build BlackLab with Maven
RUN cd "BlackLab" && \
mvn clean install

##
# Build Python + Node dependencies
##

# Install system deps with Alpine Linux package manager
RUN apk add --update --no-cache \
g++ \
gcc \
make \
openssl-dev \
python3-dev \
python \
py-pip \
nodejs

# Install Python dependencies
RUN pip install -r "requirements.txt" && \
npm install --no-optional && \
npm run build

# Store Mongo service name as mongo host
ENV MONGO_HOST=mongo_service
ENV TOMCAT_HOST=tomcat_service
ENV TOMCAT_WEBAPPS=/tomcat_webapps/

# Make ports available
EXPOSE 7082

# Seed the db
CMD npm run seed && \
gunicorn -b 0.0.0.0:7082 --access-logfile - --reload server.app:app

完整的 docker-compose.yml
version: '2'

services:
tomcat_service:
image: 'bitnami/tomcat:latest'
ports:
- '8080:8080'
volumes:
- docker-data-tomcat:/bitnami/tomcat/data/
- docker-data-blacklab:/lts-app/lts/

mongo_service:
image: 'mongo'
command: mongod
ports:
- '27017:27017'

web:
# gain access to linked containers
links:
- mongo_service
- tomcat_service
# explicitly declare service dependencies
depends_on:
- mongo_service
- tomcat_service
# set environment variables
environment:
PYTHONUNBUFFERED: 'true'
# use the image from the Dockerfile in the cwd
build: .
ports:
- '7082:7082'
volumes:
- docker-data-tomcat:/tomcat_webapps
- docker-data-blacklab:/lts-app/lts/


volumes:
docker-data-tomcat:
docker-data-blacklab:

我正在运行的命令是: docker-compose up --build
Amazon Linux 上的结果是:
 Running setup.py install for pymongo: started
Running setup.py install for pymongo: finished with status 'done'
Running setup.py install for pluggy: started
Running setup.py install for pluggy: finished with status 'done'
Running setup.py install for coverage: started
Running setup.py install for coverage: finished with status 'done'
Successfully installed Faker-0.8.12 Flask-0.12.2 Flask-Cors-3.0.3 Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 astroid-1.6.2 attrs-17.4.0 backports.functools-lru-cache-1.5 beautifulsoup4-4.5.1 click-6.7 configparser-3.5.0 coverage-4.5.1 enum34-1.1.6 funcsigs-1.0.2 futures-3.2.0 gunicorn-19.7.1 ipaddress-1.0.19 isort-4.3.4 itsdangerous-0.24 lazy-object-proxy-1.3.1 mccabe-0.6.1 more-itertools-4.1.0 pluggy-0.6.0 py-1.5.3 py4j-0.10.6 pylint-1.8.3 pymongo-3.6.1 pytest-3.5.0 pytest-cov-2.5.1 python-dateutil-2.7.2 singledispatch-3.4.0.3 six-1.11.0 text-unidecode-1.2 wrapt-1.10.11
You are using pip version 8.1.2, however version 9.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
npm WARN deprecated redux-mock-store@1.5.1: breaking changes in minor version

> base62@1.2.7 postinstall /lts-app/node_modules/base62
> node scripts/install-stats.js || exit 0



ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r "requirements.txt" && npm install --no-optional && npm run build' returned a non-zero code: 1

有谁知道可能导致这种差异的原因是什么?来自 Docker 的错误消息并没有提供太多线索。我将非常感谢其他人可以提供的任何想法!

最佳答案

为了解决这个问题,我按照@MazelTov 的建议在我的本地 OSX 开发机器上构建了容器,然后将图像发布到 Docker Cloud,然后将这些图像拉到我的生产服务器 (AWS EC2) 上并运行这些图像。

安装依赖项

我将尝试概述我在下面遵循的步骤,以防他们帮助他人。请注意,这些步骤要求您在开发和生产机器上安装 docker 和 docker-compose。我使用 gui 安装程序来安装 Docker for Mac。

构建镜像

编写 Dockerfile 和 docker-compose.yml 文件后,您可以使用 docker-compose up --build 构建镜像.

将图像上传到 Docker 云

构建镜像后,您可以通过以下步骤将它们上传到 Docker Cloud。首先,在 Docker Cloud 上创建一个帐户.

然后将您的 Docker Cloud 用户名存储在环境变量中(因此您的 ~/.bash_profile 应该包含 export DOCKER_ID_USER='yaledhlab'(尽管使用您的用户名)。

下次从您的开发者机器登录到您的帐户:
docker login
登录后,列出您的 docker 镜像:
docker ps
这将显示如下内容:

CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                      NAMES
89478c386661 yaledhlab/let-them-speak-web "/bin/sh -c 'npm run…" About an hour ago Up About an hour 0.0.0.0:7082->7082/tcp letthemspeak_web_1
5e9c75d29051 training/webapp:latest "python app.py" 4 hours ago Up 4 hours 0.0.0.0:5000->5000/tcp heuristic_mirzakhani
890f7f1dc777 bitnami/tomcat:latest "/app-entrypoint.sh …" 4 hours ago Up About an hour 0.0.0.0:8080->8080/tcp letthemspeak_tomcat_service_1
09d74e36584d mongo "docker-entrypoint.s…" 4 hours ago Up About an hour 0.0.0.0:27017->27017/tcp letthemspeak_mongo_service_1

对于要发布到 Docker Cloud 的每个图像,运行:
docker tag image_name $DOCKER_ID_USER/my-uploaded-image-name
docker push $DOCKER_ID_USER/my-uploaded-image-name

例如,要上传 mywebapp_web到您在 Docker 云上的用户帐户,您可以运行:
docker tag mywebapp_web $DOCKER_ID_USER/web
docker push $DOCKER_ID_USER/web

然后您可以运行 open https://cloud.docker.com/swarm/$DOCKER_ID_USER/repository/list查看您上传的图片。

部署镜像

最后,您可以通过以下步骤在 EC2 上部署您的镜像。首先,在 Amazon 风格的 EC2 实例上安装 Docker 和 Docker-Compose:
# install docker
sudo yum install docker -y

# start docker
sudo service docker start

# allow ec2-user to run docker
sudo usermod -a -G docker ec2-user

# get the docker-compose binaries
sudo curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

# change the permissions on the source
sudo chmod +x /usr/local/bin/docker-compose

注销,然后重新登录以更新您的用户组。然后启动一个屏幕并运行服务器: screen .屏幕启动后,您应该能够添加一个新的 docker-compose 配置文件,该文件指定已部署图像的路径。例如,我需要获取 let-them-speak-web装在 yaledhlab 内的容器的 Docker Cloud 帐户,所以我更改了 docker-compose.yml将上面的文件复制到下面的文件,我将其命名为 production.yml :
version: '2'

services:
tomcat_service:
image: 'bitnami/tomcat:latest'
ports:
- '8080:8080'
volumes:
- docker-data-tomcat:/bitnami/tomcat/data/
- docker-data-blacklab:/lts-app/lts/

mongo_service:
image: 'mongo'
command: mongod
ports:
- '27017:27017'

web:
image: 'yaledhlab/let-them-speak-web'
# gain access to linked containers
links:
- mongo_service
- tomcat_service
# explicitly declare service dependencies
depends_on:
- mongo_service
- tomcat_service
# set environment variables
environment:
PYTHONUNBUFFERED: 'true'
ports:
- '7082:7082'
volumes:
- docker-data-tomcat:/tomcat_webapps
- docker-data-blacklab:/lts-app/lts/

volumes:
docker-data-tomcat:
docker-data-blacklab:

然后可以运行生产 compose 文件: docker-compose -f production.yml up .最后,使用另一个终端 ssh 进入,并使用 screen -D 分离屏幕.

关于Docker 容器基于 OSX 而不是 Amazon Linux 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49500254/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com