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.
2
Answers
So keep it running.
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&&
byset -e
, you can read about it https://mywiki.wooledge.org/BashFAQ/105 .If you want to do some modification and then start nginx, you should:
docker inspect
the docker image and get the command it uses, or inspect the Dockerfile the image was built withYou’re trying to set an individual container’s
command:
to copy some code into the container, every time it starts up. It’d be better to write a Dockerfile to do this work, only once. You can start a DockerfileFROM
any image you want and do any setup work you need to do in the container. It will inherit theENTRYPOINT
and/orCMD
from the base image if you don’t override them.Then in your Compose file, specify to
build:
an image instead of using the Docker Hubimage:
; do not overridecommand:
; and do not overwrite parts of the image with named volumes.