简体   繁体   中英

Folder missing inside docker container

I wrote this docker-compose project. The docker-compose.yml looks like this:

version: '3.1'

services:
  db:
    image: mysql
    restart: always
    environment:
      - MYSQL_DATABASE=mgsv
      - MYSQL_USER=mgsv_user
      - MYSQL_PASSWORD=mgsvpass
      - MYSQL_ROOT_PASSWORD=mysql123
    volumes:
      - ./mysql:/docker-entrypoint-initdb.d

  www:
    build: ./mGSV 
    restart: always
    ports:
      - 8080:8080

And the Dockerfile is based on a PHP container and looks like this.

FROM php:5-apache

RUN apt-get update  && apt-get install -y --no-install-recommends \
                openjdk-7-jdk \
                maven  \
        git \
        && rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/qunfengdong/mGSV.git

# Move the folder 'mgsv' to DocumentRoot of Apache web server. By default, the DocumentRoot of Apache is /var/www/ (speak to the system administrator to know the exact DocumentRoot).
RUN cd /var/www/html/mGSV \
    && mkdir tmp \
    && chmod -R 777 tmp

RUN cd /var/www/html/mGSV && sed -i.bak "s|'gsv'|'mgsv_user'|" lib/settings.php \ 
    && sed -i.bak "s|$database_pass = ''|$database_pass = 'mgsvpass'|" lib/settings.php \
    && sed -i.bak "s|cas-qshare.cas.unt.edu|localhost|" lib/settings.php

RUN cp /var/www/html/mGSV/Arial.ttf /usr/share/fonts/truetype/

RUN cd /var/www/html/mGSV/ws \
    && tar -xzf mgsv-ws-server.tar.gz

RUN cd /var/www/html/mGSV/ws/mgsv-ws-server \ 
    && mvn package

RUN cp -f /var/www/html/mGSV/ws/mgsv-ws-server/target/ws-server-1.0RC1-jar-with-dependencies.jar /var/www/html/mGSV/ws/

RUN cd /var/www/html/mGSV/ws \ 
    && echo "mgsv_upload_url=http://localhost/mgsv" > config.properties \
    && echo "ws_publish_url=http\://localhost\:8081/MGSVService" >> config.properties \
    && java -jar ws-server-1.0RC1-jar-with-dependencies.jar &

This is the output which I got:

Step 1/11 : FROM php:5-apache
 ---> 8f4a38cf4542
Step 2/11 : RUN apt-get update  && apt-get install -y --no-install-recommends                 openjdk-7-jdk                 maven       git         && rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> f194797b9362
Step 3/11 : RUN git clone https://github.com/qunfengdong/mGSV.git
 ---> Using cache
 ---> 4acd066da444
Step 4/11 : RUN cd /var/www/html/mGSV     && mkdir tmp     && chmod -R 777 tmp
 ---> Using cache
 ---> f766f9ceb7d3
Step 5/11 : RUN cd /var/www/html/mGSV && sed -i.bak "s|'gsv'|'mgsv_user'|" lib/settings.php     && sed -i.bak "s|$database_pass = ''|$database_pass = 'mgsvpass'|" lib/settings.php     && sed -i.bak "s|cas-qshare.cas.unt.edu|localhost|" lib/settings.php
 ---> Using cache
 ---> 007dff8907f4
Step 6/11 : RUN cp /var/www/html/mGSV/Arial.ttf /usr/share/fonts/truetype/
 ---> Using cache
 ---> 026049ca32d8
Step 7/11 : RUN cd /var/www/html/mGSV/ws     && tar -xzf mgsv-ws-server.tar.gz
 ---> Using cache
 ---> 92a0f85b27a0
Step 8/11 : RUN cd /var/www/html/mGSV/ws/mgsv-ws-server     && mvn package
 ---> Using cache
 ---> 5aa1723f255f
Step 9/11 : RUN cp -f /var/www/html/mGSV/ws/mgsv-ws-server/target/ws-server-1.0RC1-jar-with-dependencies.jar /var/www/html/mGSV/ws/
 ---> Using cache
 ---> f0dbd0ac1ddb
Step 10/11 : RUN cd /var/www/html/mGSV/ws     && echo "mgsv_upload_url=http://localhost/mgsv" > config.properties     && echo "ws_publish_url=http\://localhost\:8081/MGSVService" >> config.properties     && java -jar ws-server-1.0RC1-jar-with-dependencies.jar &
 ---> Using cache
 ---> 0c86c0adddd5

However, when I create an interactive session the /var/www/html/ is empty:

$ docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
php                                    5-apache            8f4a38cf4542        7 days ago          374MB

$ sudo docker run --entrypoint /bin/bash -i -t 8f4a38cf4542
root@a3908e297bcf:/var/www/html# ls

Why can't I see the /var/www/html/mGSV folder inside the docker container?

Thank you in advance.

Michal

The 8f4a38cf4542 image is the php:5-apache base image you are building FROM before all your additions.

The docker-compose build output should include a line: Successfully built eccdcc9a9534 at the end, which is the image ID you need to copy from your output and use. You should be able to find this image in the complete output:

docker images -a

To make life easier, add an image name to the www service so compose tags the build and it's easily accessable:

www:
  build: ./mGSV
  image: user3523406/www
  restart: always

Then

sudo docker run --entrypoint /bin/bash -it user3523406/www

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM