首页 > 解决方案 > 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,所以当我按该顺序执行命令时:

  1. docker build --tag myapp:0 。
  2. docker run -d -t myapp:0
  3. docker exec -it <container_id> /bin/bash

它按预期工作。

由于某种原因,使用 docker compose 时容器无法正常工作...

命令顺序:

  1. docker-compose up -d --build
  2. 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 *

标签: dockerdocker-compose

解决方案


推荐阅读