Problem managing directory in dockerfile

Hi, I have installed docker ce on ubuntu server 16.04.
I’m newbie in Docker and I’m trying to write a docker file.
My intent is to get a “Lamp image” and prepare it for creating a new image ready for launch a new Drupal installation.
I created a new folder with a subfolder called “drupal” that contains the drupal’s installation files.
in my new folder I created this “dockerfile”:

FROM fauria/lamp
WORKDIR /app
ADD . /app

RUN service apache2 start
RUN service mysql start
RUN mv /app/drupal /var/www/html
RUN cd /var/www/html/drupal
RUN cp ./sites/default/default.settings.php ./sites/default/settings.php

EXPOSE 80

but this doesn’t work: I received an error while executing the last “cp” command:
“no such file or directory”.
What’s I’m doing wrong?
I don’t know if I have to use RUN or CMD for my intent: what’s correct approach?

I thank you in advance for every suggestions

ADD and COPY run on the HOST to move host files to the image

RUN happens IN the image, but cannot see HOST files.

my “ADD . /app” statement does not copy the “drupal” directory? (present at the same level of the dockerfile)

change it to COPY instead of ADD

thank you, with COPY instead of ADD the folder has been copied in /app/drupal
but I’m afraid I did not understand how docker works cause the next three instructions (I tried to run the script with only the first three RUN instructions) do not seem to have an effect, although I do not receive any error message.
I executed this command:
docker build -t demodrupal .
everything seems to work fine… but I dont understand, if i try to execute this command…
docker run -it demodrupal /bin/bash
and then
ls /var/www/html
I can’t see drupal folder…
if I execute this command: service apache2 status the response is "apache2 is not running"
maybe I’m confusing … I’d like to understand what I’m wrong

1 Like

there is no ‘service’ command, so that will be one thing…

a container is designed for ONE application…
the container MUST have something that runs in the foreground to keep the container alive,

if u look at the apache image you will see it is running apache -foreground.

the lamp image probably already has a /var/www/html, so your move would have failed.

you should see the output of the run commands in the docker build output

Ok I made progress! I copied “drupal” folder to “/var/www/html/drupal” but I need one more thing:
the folder now has owner “root”, group “root” and mod 755.
I need to change this permissions and I tried with
RUN chgrp -R www-data /var/www/html/drupal
RUN chmod -R 775 /var/www/html/drupal
but no way! never works!
how can I get the desired result?
thank you very much for help

the user www-data doesn’t exist in the container… you have to add it

RUN useradd -ms /bin/bash www-data

but the chmod should have worked

first command is to change group… www-data is a group… I tried
RUN groupadd www-data and response is “www-data already exists”

ok… and after the chgrp?

RUN ls -laF /var/www/html/drupal

after chgrp it has no effect because every files and subfolders still show “root” as group

The problem depends on the image I was using.
Unfortunately it was my very first tests with docker and I had not yet used other images: for example, with the image “tutum/lamp” the instructions to change group and permissions works.
For example for my new working test I used:
COPY ./drupal /drupal
RUN mv /drupal /var/www/html/drupal && chgrp -R www-data /var/www/html/drupal &&\
chmod -R 775 /var/www/html/drupal
these commands work

progress. good work… thanks for the update