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"

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

Then Dockerfile from app folder

FROM php:7.1.2


RUN apt-get update
RUN curl -sS | 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 "" >> mongodb.ini

ADD /home/
RUN chmod +x /home/

ADD mongo /


CMD ["/home/"]

Then in my 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=" "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=" "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

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

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.