Git clone doesnt download the folder within container

Hi

Im trying from a few files (dockerfile, docker-compose and config files), create a laravel project from scratch with just running ‘docker-compose up -d’.

The problem come when I RUN git clone … I am not able to see the repository neither the container or my local.

Anyone knows why? I dont see any errors.


FROM php:7.2-fpm

Set working directory

WORKDIR /var/www

Install dependencies

RUN apt-get update && apt-get install -y
build-essential
libpng-dev
libjpeg62-turbo-dev
libfreetype6-dev
locales
zip
jpegoptim optipng pngquant gifsicle
vim
unzip
git
curl

RUN git clone https://github.com/laravel/laravel.git blog

You post the content of a Dockerfile (not docker-compose.yml)
When building the container, it’ll draw the php image, update/upgrades it and add e few more packages. Finally it clones laravel and that’s it.
While you won’t see any problems building, when running it the container will just pop-up a few seconds (at best) and then terminates itself as it has no active task.
Containers without any running task will automatically terminated - that’s the design.

So what you need is an “entrypoint” that triggers a continuous process. E.g running an nginx (not in daemon mode), some python/java server-application or a simple “infinite loop”.

For example:

ENTRYPOINT ["tail", "-f", "/dev/null"]

This will keep the container running and you’ll see it via “docker ps”.

Thanks a lot mgabeldocker for your reply.

Just for my records… are you saying that i need to use ENTRYPOINT to get the repository cloned withing my container and therefore, in my local computer to work with.

My goal is just running a command ‘docker-compose up -d’… to deploy a laravel proyect to start working with.

Thanks

Well … no. First: docker and docker-compose are two different things:
A Dockerfile is a simple text file that contains the commands a user could call to assemble an image whereas Docker Compose is a tool for defining and running multi-container Docker applications.

If you have a docker container it will only exist as long as an active (foreground) task is running. If that task is killed, crashes or gets otherwise terminated, the whole container dies.

However, I checked the github page of the Laravel Framework. Luckily these guys already offer some docker-compose based sollution.
So first of all make sure that docker-compose is installed. It’s a separate installation which has to be done on top of docker
Then clone the github repository of the Framework - cd inside the directory - and build the containers.
There’s a nice step-by-step procedure available :wink: -> https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose

Thanks mgabeldocker for your explanation.

Yes. I saw that link. Actually I started with it but i wanted to go a step forward. As you can see, you first clone the repository and after that, you add dockerfile and docker-compose.yml. What i want to achieve is to avoid all those instructions and just running a command ‘docker-compose up -d’ to deploy the whole application. That would be amazing hehe.

I found something interesting but doesn’t work unfortunately. It is to have ’ command: git clone…’ in the docker-compose.yml

#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
command: git clone https://github.com/laravel/laravel.git blog
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network

As I said, it doesnt work. The container is restarting all the time trying clone the repository over and over again. It says the folder blog is not empty.

Yes. It’s important to know exactly how works internally. Maybe you are able to run a script after the container is created? As far as I know CMD does, but only can be called once and i need it to run the server.

Hi
I checked the documentation and cloned the git to on of my dev machines just to tryout and play with it a bit.
Seems you won’t get around “Step 2 - Creating the Docker Compose File” (and following…).
You’ll manually have to create the docker-compose.yml file and put the necessary parameters into it accordingly.

I don’t know where you got your docker-compose file from (as shown in your post) but this one looks like it’s just temporally used by the “Composer” to get some necessary stuff - as written in Step 1

Hi

I follow all the steps and I got it running well. I have no problem with the tutorial of Digital Ocean. As you can see there are many steps and instructions that i want to avoid. My goal is to get the same result as the tutorial, just running a command… ‘docker-compose up -d’
In order to do that i need in somehow to run git clone inside of a dockerfile, docker-compose or wherever… but so far i am not able to do so.

I’ll carry on with the research. Hopefully it is possible to do it. :slight_smile: