Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将显示复制到Docker图像的文件_Docker_Docker Compose - Fatal编程技术网

将显示复制到Docker图像的文件

将显示复制到Docker图像的文件,docker,docker-compose,Docker,Docker Compose,我有一个多阶段的Dockerfile。我在构建映像中制作一个程序,对内容加焦油,在主映像中复制它,解压它。一旦容器启动,当我进入容器时,我就再也找不到文件了。然而,使用“ls”命令,我可以看到它被复制和提取。我不知道这是否与我将应用程序的根目录作为卷这一事实有关。我这样做是为了在修改代码后加快构建速度 docker-compose.yml version: "3" services: web: build: . ports: - "5000:5000"

我有一个多阶段的Dockerfile。我在构建映像中制作一个程序,对内容加焦油,在主映像中复制它,解压它。一旦容器启动,当我进入容器时,我就再也找不到文件了。然而,使用“ls”命令,我可以看到它被复制和提取。我不知道这是否与我将应用程序的根目录作为卷这一事实有关。我这样做是为了在修改代码后加快构建速度

docker-compose.yml

version: "3"
services:
  web:
    build: .
    ports:
      - "5000:5000"
      - "5432:5432"
    volumes:
      - ".:/code"
    environment:
      - PORT=5000
      # TODO: Should be set to 0 for production
      - PYTHONUNBUFFERED=1
Dockerfile

# Build lab-D
FROM gcc:8.2.0 as builder
RUN  apt-get update && apt-get install -y libxerces-c-dev
WORKDIR /lab-d/
RUN git clone https://github.com/lab-d/lab-d.git
WORKDIR /lab-d/lab-d/
RUN autoreconf -if
RUN ./configure --enable-silent-rules 'CFLAGS=-g -O0 -w' 'CXXFLAGS=-g -O0 -w' 'LDFLAGS=-g -O0 -w'
RUN make
RUN make install
WORKDIR /lab-d/
RUN ls
RUN tar -czf labd.tar.gz lab-d


# Main Image
FROM library/python:3.7-stretch
RUN apt-get update && apt-get install -y python3 python3-pip \
    postgresql-client \
    # lab-D requires this library
    libxerces-c-dev \
    # For VIM
    apt-file 

RUN apt-file update && apt-get install -y vim

RUN pip install --upgrade pip

COPY requirements.txt /
RUN pip3 install --trusted-host pypi.org -r /requirements.txt

RUN pwd
RUN ls .
COPY --from=builder /lab-d/labd.tar.gz /code/labd.tar.gz
WORKDIR /code
RUN pwd
RUN ls .
RUN tar -xzf labd.tar.gz
RUN ls .
run pwd
RUN ls .

CMD ["bash", "start.sh"]
docker compose构建--无缓存

...
Step 19/29 : RUN pwd
 ---> Running in a856867bf69a
/
Removing intermediate container a856867bf69a
 ---> f1ee3dca8500
Step 20/29 : RUN ls .
 ---> Running in ee8da6874808
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
requirements.txt
root
run
sbin
srv
sys
tmp
usr
var
Removing intermediate container ee8da6874808
 ---> e8aec80955c9
Step 21/29 : COPY --from=builder /lab-d/labd.tar.gz /code/labd.tar.gz
 ---> 72d14ab4e01f
Step 22/29 : WORKDIR /code
 ---> Running in 17873e785c17
Removing intermediate container 17873e785c17
 ---> 57e8361767ca
Step 23/29 : RUN pwd
 ---> Running in abafd210abcb
/code
Removing intermediate container abafd210abcb
 ---> c6f430e1b362
Step 24/29 : RUN ls .
 ---> Running in 40b9e85261c2
labd.tar.gz
Removing intermediate container 40b9e85261c2
 ---> f9ee8e04d065
Step 25/29 : RUN tar -xzf labd.tar.gz
 ---> Running in 6e60ce7e1886
Removing intermediate container 6e60ce7e1886
 ---> 654d3c791798
Step 26/29 : RUN ls .
 ---> Running in 0f445b35f399
lab-d
labd.tar.gz
Removing intermediate container 0f445b35f399
 ---> 7863a15534b1
Step 27/29 : run pwd
 ---> Running in 9658c6170bde
/code
Removing intermediate container 9658c6170bde
 ---> 8d8e472a1b95
Step 28/29 : RUN ls .
 ---> Running in 19da5b77f5b6
lab-d
labd.tar.gz
Removing intermediate container 19da5b77f5b6
 ---> 140645efadbc
Step 29/29 : CMD ["bash", "start.sh"]
 ---> Running in 02b006bdf868
Removing intermediate container 02b006bdf868
 ---> 28d819321035
Successfully built 28d819321035
Successfully tagged -server_web:latest
start.sh

#!/bin/bash

# Start the SQL Proxy (Local-only)
pwd
ls .
./cloud_sql_proxy -instances=api-project-123456789:us-central1:sq=tcp:5432 \
                  -credential_file=./config/google_service_account.json &
ls .            
# Override with CircleCI for other environments
cp .env.development .env
ls .
python3 -u ./server/server.py

在您的
Dockerfile

COPY --from=builder /lab-d/labd.tar.gz /code/labd.tar.gz
WORKDIR /code
RUN tar -xzf labd.tar.gz
但是您的
docker compose.yml
指定

volumes:
  - ".:/code"
这会导致主机上的当前目录装载到容器中的
/code
上,Dockerfile所做的每一项工作都会被隐藏