docker-compose构建失败,找不到文件

时间:2020-09-11 20:22:36

标签: docker docker-compose tomcat8

我想问一个关于docker-compose.yml和Dockerfile的问题。 以下是我遇到的情况。

  1. 我首先使用 docker image build(docker image build -t test。) docker run(docker run -p 8888:8080 -p 8889:8009 8883:8443 -v tomcat8 :// usr / local / tomcat8 --name测试),以测试我的Dockerfile是否准备就绪,并且可以正常工作。

Dockerfile

FROM ubuntu:latest

ENV HOME /usr/local/tomcat8

RUN apt-get -y update && apt-get -y install unzip wget openjdk-8-jdk

COPY ./installERDDAP.sh $HOME/installERDDAP.sh

COPY . $HOME/

RUN chmod +x $HOME/installERDDAP.sh

WORKDIR $HOME

RUN ./installERDDAP.sh

EXPOSE 8080 8443 8009

CMD ["catalina.sh","run"]
  1. 以便我编写docker-compose.yml脚本,如下所示

docker-compose.yml

version: '3'

services:
   erddap:
      build:
         context: ./
         dockerfile: Dockerfile
      image: erddap_dev:2.02
      container_name: erddap
      restart: always
      ports:
         - "8888:8080"
         - "8883:8443"
         - "8889:8009"
      volumes:
         - ./tomcat8:/usr/local/tomcat8
  1. 但是,错误消息弹出并显示文件 catalina.sh 不存在。当我进入容器时,那是真的。没有文件。但是,如果我将RUN ls -la放在 Dockerfile 中,我确实会看到文件已列出,如下所示。
Step 12/14 : RUN ls -la
 ---> Running in fed4870bd617
total 176
drwxr-xr-x. 1 root root  4096 Sep 11 20:08 .
drwxr-xr-x. 1 root root    21 Sep 11 20:08 ..
drwxrwxr-x. 8 root root   166 Sep 11 19:31 .git
-rw-rw-r--. 1 root root    12 Sep 11 07:50 .gitignore
-rw-r--r--. 1 root root   165 Sep 11 20:08 .wget-hsts
-rw-r-----. 1 root root 19318 Jun 30 21:53 BUILDING.txt
-rw-r-----. 1 root root  5408 Jun 30 21:53 CONTRIBUTING.md
-rw-rw-r--. 1 root root   640 Sep 11 20:03 Dockerfile
-rw-r-----. 1 root root 57011 Jun 30 21:53 LICENSE
-rw-r-----. 1 root root  1726 Jun 30 21:53 NOTICE
-rw-r-----. 1 root root  3255 Jun 30 21:53 README.md
-rw-r-----. 1 root root  7136 Jun 30 21:53 RELEASE-NOTES
-rw-r-----. 1 root root 16262 Jun 30 21:53 RUNNING.txt
drwxr-x---. 2 root root  4096 Sep 11 20:08 bin
-rwxr-x---. 2 root root 25245 Jun 30 21:50 catalina.sh
drwx------. 2 root root   238 Jun 30 21:53 conf
drwxr-xr-x. 3 root root    20 Sep 11 20:08 content
drwxr-xr-x. 2 root root     6 Sep 11 20:08 data
drwxrwxr-x. 5 root root    44 Sep 11 03:46 doc
-rw-rw-r--. 1 root root   320 Sep 11 19:49 docker-compose.yml
-rwxrwxr-x. 1 root root  1030 Sep 11 19:41 installERDDAP.sh
drwxr-x---. 2 root root  4096 Sep 11 20:08 lib
drwxr-x---. 2 root root     6 Jun 30 21:49 logs
drwxr-xr-x. 2 root root    66 Sep 11 20:08 tarz
drwxr-x---. 2 root root    30 Sep 11 20:08 temp
drwxrwxr-x. 4 root root    29 Sep 11 19:41 tomcat8
drwxr-x---. 7 root root    99 Sep 11 20:08 webapps
drwxr-x---. 2 root root     6 Jun 30 21:49 work
Removing intermediate container fed4870bd617

有趣的是,这些文件也没有显示在我的卷目录中。可以请人告诉我我在哪里错了吗?

谢谢


第一次更新:

  • 根据以下建议,如果我推荐 docker-compose.yml 中的卷,或者我在CMD命令之前添加了 WORKDIR / ,但没有一个起作用。

  • 如果我将 Dockfile 中推荐的CMD从 CMD [“ catalina.sh”,“运行”] 修改为 CMD [“。/catalina .sh“,”运行“] 也不起作用。但是,如果我更改为 CMD [“ /usr/local/tomcat8/catalina.sh”,“运行”] ,则构建过程已完成。但是错误却变得

Attaching to erddap
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program
erddap    | Cannot find /usr/local/bin/setclasspath.sh
erddap    | This file is needed to run this program

第二次更新:

installERDDAP.sh

#!/bin/bash
mkdir tarz

wget -q https://ftp.wayne.edu/apache/tomcat/tomcat-8/v8.5.57/bin/apache-tomcat-8.5.57.tar.gz -O ./tarz/apache-tomcat-8.5.57.tar.gz
tar -xf ./tarz/apache-tomcat-8.5.57.tar.gz -C /usr/local/tomcat8 --strip 1


mkdir data

ln ./bin/catalina.sh catalina.sh

2 个答案:

答案 0 :(得分:1)

根据我的判断,您的绑定安装可能是“覆盖/隐藏”您的容器文件。如果您的“ ./tomcat8”目录不为空,则它将基本上“覆盖/隐藏”容器中的文件。我将删除卷声明以验证是否是这种情况,如果是这样,则需要清除“ ./tomcat8”目录,并且在再次运行容器时,应使用容器中的文件填充它。转发本地目录将再次“覆盖/隐藏”您的容器文件。

答案 1 :(得分:0)

CMD ["catalina.sh","run"]行之前的docker文件中,将WORKDIR /更改为“ ./catalina.sh”