docker - docker-compose.yml - 在 Ubuntu 主机上具有退出状态的容器
问题描述
我的 docker-compose.yml:
version: "3.3"
services:
build_and_run_service:
image: myapp:0
build: .
network_mode: host
volumes:
- './bin/cookie:/app/cookie'
- './bin/logs:/app/logs'
- './bin/warehouse:/app/warehouse'
Dockerfile 不包含 CMD 和 ENTRYPOINT,所以当我按该顺序执行命令时:
- docker build --tag myapp:0 。
- docker run -d -t myapp:0
- docker exec -it <container_id> /bin/bash
它按预期工作。
由于某种原因,使用 docker compose 时容器无法正常工作...
命令顺序:
- docker-compose up -d --build
- docker-compose run -d build_and_run_service bash
怎么了?
这两种情况在 Windows 上都可以正常工作,但在 Ubuntu 上却不行……
#edit Dockerfile: FROM ubuntu:20.04 as runtime LABEL description="Build and run container - myapp"
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-get install -y nano
RUN apt-get install -y wget
RUN apt-get install -y curl
RUN apt-get install -y make
RUN apt-get install -y build-essential
RUN apt-get install -y tcl zlib1g-dev libssl-dev tk libcurl4-gnutls-dev libexpat1-dev gettext dos2unix
# Compilers
RUN apt-get install -y gcc-10
RUN apt-get install -y g++-10
RUN rm /usr/bin/gcc \
&& ln -s /usr/bin/gcc-10 /usr/bin/gcc
RUN rm /usr/bin/g++ \
&& ln -s /usr/bin/g++-10 /usr/bin/g++
# Postgres dev
RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
RUN wget --no-check-certificate --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update
RUN apt-get install -y libpq-dev postgresql-server-dev-13
RUN cd /tmp \
&& wget --no-check-certificate https://www.openssl.org/source/openssl-1.1.1g.tar.gz \
&& tar -zxf openssl-1.1.1g.tar.gz \
&& cd openssl-1.1.1g \
&& ./config \
&& make \
&& make install \
&& rm /usr/bin/openssl \
&& ln -s /usr/local/bin/openssl /usr/bin/openssl \
&& ldconfig
RUN cd /tmp \
&& wget --no-check-certificate https://cmake.org/files/v3.19/cmake-3.19.6-Linux-x86_64.tar.gz \
&& tar -zxf cmake-3.19.6-Linux-x86_64.tar.gz \
&& mv cmake-3.19.6-Linux-x86_64 /usr/local/ \
&& ln -s /usr/local/cmake-3.19.6-Linux-x86_64/bin/cmake /usr/bin/cmake
RUN cd /tmp \
&& wget --no-check-certificate https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.31.0.tar.gz \
&& tar -zxf git-2.31.0.tar.gz \
&& cd git-2.31.0 \
&& make prefix=/usr/local all \
&& make prefix=/usr/local install
RUN cd /tmp \
&& wget --no-check-certificate https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz \
&& tar -zxf boost_1_75_0.tar.gz \
&& cd boost_1_75_0 \
&& ./bootstrap.sh \
&& ./b2 \
&& ./b2 install
VOLUME ["/app/cookie", "/app/logs", "/app/warehouse"]
WORKDIR /app
COPY . /src
RUN cd /src \
&& mkdir build \
&& cd build
# Some building command
## PRIVATE ##
# Removes tmp
RUN cd /tmp \
&& rm -r *
解决方案
推荐阅读
- python-3.x - 如何将机器学习模型 pickle 存储到 azure blob 并检索它/
- python - 使用 tidydata 原则在 pandas/python 中进行 Groupby 突变等效
- json - 在 Go 中检查嵌套指针结构是否为 nil 的简洁方法?
- kubernetes - 从 Kubernetes 中相同命名空间中运行的进程中删除 ClusterRoleBinding 和命名空间
- postgresql - SELECT INTO 一个临时表然后在提交时删除
- mongodb - 在 mongodb 中使用其他类型的 _id 进行分片
- git - 如何使 ssh keygen 正常工作以设置用于克隆和其他目的的 ssh 密钥
- php - 如何用现有的 PHP 文件替换 PHP 文件
- powershell - 即使打开了文件,Powershell 命令也可以格式化 USB 驱动器
- google-bigquery - 如何以流模式将数据从 AWS RDS 加载到 Google BigQuery?