Vana
Vana

Reputation: 931

Docker container always restarting

I try to start a Docker container from debian image, with a Docker compose file. But when I do docker ps - a, the container is always restarting. I don't know why :s

Here my dockerfile :

FROM debian:jessie
ENV DEBIAN_FRONTEND noninteractive
RUN mkdir /home/server
RUN cd /home/server
VOLUME /home/server
CMD /bin/bash

Here my docker compose file :

version: '2'
 services:
server:
 build: .
 restart: always
 container_name: server
 volumes:
   - "/home/binaries:/home/server"

Upvotes: 2

Views: 5957

Answers (1)

Philipp Claßen
Philipp Claßen

Reputation: 43969

When docker-compose runs your "server" container, it will immediately terminate. A docker container needs at least one running process, otherwise, the container will exit. In your example, you are not starting a process that keeps alive.

As you have configured restart: always, docker-compose will endlessly restart new containers for "server". That should explain the behavior that you describe.

I have seen docker-compose files, where data containers were defined which only mounted images (in combination with volumes_from). They deliberately used /bin/true as a command, which also lead to permanent but harmless restarts. For example:

data:
  restart: always
  image: postgres:latest
  volumes:
    - /var/lib/postgresql
  command: "true"

If restarts are not what you want, you could start a process in the container that does something useful, like running a web server or a database. But a bash alone is not something that will keep a container alive. A bash running in non-interactive mode will exit immediately.

Upvotes: 3

Related Questions