Home > Back-end >  I am trying to keep a container running using a docker compose file. I added tty: true and std_in: t
I am trying to keep a container running using a docker compose file. I added tty: true and std_in: t

Time:10-10

Here is my docker compose file.

version: '3'
services:
    web:
        image: emarcs/nginx-git
        ports:
            - 8081:80
        container_name: Avida
        working_dir: /usr/share/nginx/html
        command: bash -c "git clone https://github.com/raju/temp.git && echo "cloned successfully" && mv Avida-ED-Eco /usr/share/nginx/html && echo "Successfully moved the file""
             
        volumes:
             - srv:/srv/git
             - logs:/var/log/nginx
        environment:
            GIT_POSTBUFFER: 1048576  
        stdin_open: true 
        tty: true 
    firefox:
        image: jlesage/firefox
        ports:
            - 5800:5800
        volumes: 
            - my-vol:/data/db
        depends_on: 
            - web
volumes:
     my-vol:
        driver: local
     srv:
        driver : local
     logs:
        driver : local

What I am doing is I am using a docker nginx image with git installed on it and using that image to clone a directory and moving that directory to ngnix HTML path to read it. but after cloning the container exits and the code goes away. How can I keep container running without exiting with code 0. I tried some options such as tty: true and std_in: true nothing works.

container exit with code 0

CodePudding user response:

So keep it running.

    command: 
     - bash
     - -ec
     - | 
       git clone https://github.com/raju/temp.git
       echo "cloned successfully"
       mv -v Avida-ED-Eco /usr/share/nginx/html
       echo "Successfully moved the file""
       # keep it running
       sleep infinity
         

But you would rather create a Dockerfile, in which you would prepare the image.

I changed the format, you can read about | in YAML documentation. I replaced && by set -e, you can read about it https://mywiki.wooledge.org/BashFAQ/105 .

  • Related