Don't run container after build

Is there any way to not run a container automatically after compose?

That container should mount a volume first and then run.

If I start to container without mounting volume the script start to clone the project inside the container.

Can you post a copy of your Dockerfile?

I feel like I’m missing a detail in your question, because volume mounting is part of the docker run command; I don’t think there’s a way to add attached volumes after the fact. There might be. But this is one of the totally routine cases where you need to docker rm the container to change its basic setup. (And, correspondingly, why you should plan for containers to be routinely docker rm’d.)

A container cloning code on startup seems very odd to me. I’d add the Dockerfile to the application code repository, and have it do something like COPY . /usr/src/app to copy the application code in. Then when you make an update, after you run your local tests outside the Docker environment, you can docker build (or docker-compose build) to get a new image with the new code.

Hi @dmaze , I did something like this:

version: "3.0"

services:
    laravel-app:
        build: app/
        links:
            - laravel-mysql
            - laravel-redis
            - laravel-mongo
        ports:
            - 80:80
        volumes:
            - /app
    laravel-mysql:
        image: mysql
        environment:
            - "MYSQL_ROOT_PASSWORD=rootpass"
            - "MYSQL_DATABASE=laravel_app"
            - "MYSQL_USER=laravel_db_user"
            - "MYSQL_PASSWORD=dbpass"
        ports: 
            - "3307:3306"
    laravel-redis: 
        image: redis
    laravel-mongo:
        image: mongo 

Then Dockerfile from app folder

FROM php:7.1.2

WORKDIR /app

RUN apt-get update
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN apt-get install zlib1g-dev && docker-php-ext-install pdo pdo_mysql zip

RUN apt-get install libcurl4-openssl-dev pkg-config libssl-dev
RUN pecl install mongodb && \
    cd /usr/local/etc/php/conf.d/ && \
    touch mongodb.ini &&  echo "extension=mongodb.so" >> mongodb.ini

ADD install.sh /home/
RUN chmod +x /home/install.sh

ADD mongo /

EXPOSE 80

CMD ["/home/install.sh"]

Then in my install.sh I have the clone:

#some functions and vars before
if [ ! -f $APP/artisan ]; then

    echo "Dir does not contain artisan, create Laravel project"

    cd $APP
    #clear any file or hidden file in special for macOs users .DS_STORE
    find . -mindepth 1 -delete
    rm -rf ./*

    #add compooser dependecies
    composer create-project laravel/laravel $APP/ --prefer-dist
    composer require predis/predis
    composer require jenssegers/mongodb

    #configure database for mongo
    appendAfterStringWithFileContent "'connections' => \[" $HOME/mongo $APP/config/database.php

    #configure env file    
    searchStringAndReplaceWith "DB_HOST=127.0.0.1" "DB_HOST=laravel-mysql" $APP/.env    
    searchStringAndReplaceWith "DB_DATABASE=homestead" "DB_DATABASE=laravel_app" $APP/.env
    searchStringAndReplaceWith "DB_USERNAME=homestead" "DB_USERNAME=laravel_db_user" $APP/.env
    searchStringAndReplaceWith "DB_PASSWORD=secret" "DB_PASSWORD=dbpass" $APP/.env
    searchStringAndReplaceWith "REDIS_HOST=127.0.0.1" "REDIS_HOST=laravel-redis" $APP/.env

    appendToFile "MONGO_DATABASE=laravel_app" $APP/.env

    #add mongo provider
    appendAfterStringWithString "RouteServiceProvider::class," "        Jenssegers\Mongodb\MongodbServiceProvider::class," $APP/config/app.php
    
fi

#start project
php $APP/artisan serve --port=80 --host=0.0.0.0

As i understand from you the flow may not be correct. So the container app should be mounted with an empty or with a Laravel project.