1

I have a simple python image in a Dockerfile:

FROM python:3.8-slim-buster
RUN apt-get -y update
RUN apt-get -y install git
RUN apt-get update \
 && apt-get install gcc -y \
 && apt-get clean
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip3 install -r requirements.txt
ENTRYPOINT ["python"]

I ran this once with a docker-compose.yml file with an restart: unless-stoped attribute. Now every time I stop the container, It immediately restarts again. It is behaving as restart: always. Even when I put in restart: no, stop the container, rebuild and docker run, the same thing keeps happening`

How can I kill this container once a for all?

More details:

This is the command that is being auto run every time (got this from doing docker inspect --format "$(curl -s https://gist.githubusercontent.com/efrecon/8ce9c75d518b6eb863f667442d7bc679/raw/run.tpl)" <container id> as suggested here :

docker run \
  --name "/src_python_run_b28e47065e14" \
  --runtime "runc" \
  --volume "/home/dir/src:/app:rw" \
  --log-driver "json-file" \
  --restart "" \
  --network "my-network_default" \
  --network-alias "src_python_run_b28e47065e14" \
  --network-alias "6116957bb6af" \
  --hostname "6116957bb6af" \
  --env "PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
  --env "LANG=C.UTF-8" \
  --env "PYTHON_VERSION=3.8.15" \
  --env "PYTHON_PIP_VERSION=22.0.4" \
  --env "PYTHON_SETUPTOOLS_VERSION=57.5.0" \
  --env "PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/66030fa0332b4914d4c4d089661a0bdeeeb274/public/get-pip.py" \
  --label "com.docker.compose.config-hash"="b2a7338a55582eb17895d8b5c2ee820d7c84ed2c900d7d7de0bb1fa787638d" \
  --label "com.docker.compose.container-number"="1" \
  --label "com.docker.compose.depends_on"="" \
  --label "com.docker.compose.image"="sha256:83d2d8f4fc6374f478b982ecc217caf34c58bccf4a497d182a6e1fe35e5e04" \
  --label "com.docker.compose.oneoff"="True" \
  --label "com.docker.compose.project"="src" \
  --label "com.docker.compose.project.config_files"="/home/dir/src/docker-compose.yml" \
  --label "com.docker.compose.project.working_dir"="/home/dir/src" \
  --label "com.docker.compose.service"="python" \
  --label "com.docker.compose.slug"="b28e47065e14275ac786d683ffcc7cc7489e3efef144d45ab9e2ad4bf48023" \
  --label "com.docker.compose.version"="2.5.0" \
  --attach stdin \
  --attach stdout \
  --attach stderr \
  --interactive \
  --entrypoint "python" \
  "src_python" \
  "-m" "test" "run" "--file" "true" 

Interesting update

As a temporary test I deleted docker-compose.yml and Dockerfile so I know no container can be restarted.

The strange thing is that, although the container stopped and is not restarting, I can still see it as a process. If I type ps aux | grep docker, there is

user  2963491  0.0  0.3 728792 24608 ?        Rl   17:01   0:00 docker-compose run python -m test run --file true

I tried killing this process but it is not working since its not fixed, the PID is changing meaning process is being stopped and restarted again. Why is this happening?

bcsta
  • 1,963
  • 3
  • 22
  • 61
  • How do you stop the container? – Hans Kilian Nov 19 '22 at 16:57
  • @HansKilian `docker stop `. Tried also removing the image exactly afterward.. but it still restarts. The only way I managed to stop this is to delete `docker-compose.yml` and deleting `Dockerfile`. But obviously this is not a solution for me since I need to use them for other services. – bcsta Nov 19 '22 at 17:04
  • You should stop it using docker-compose if you've started it with docker-compose. – Hans Kilian Nov 19 '22 at 17:26
  • what is `docker ps -a` showing? – zsolt Nov 19 '22 at 18:53
  • @HansKilian using `docker-compose stop` still automatically recreates the container – bcsta Nov 20 '22 at 09:32
  • @zsolt `docker ps -a` shows a list of container I stopped manually. All the same image but different names ex: `src_python_run_28afac65ca0b` – bcsta Nov 20 '22 at 09:33
  • You should delete those with docker rm -f containername. Also when you do compose up you should stop the compose project with compose down and not fiddle with the individual containers. Compose is using LABEL metadata to manage the project and if you mess up the project status by deleting/restarting containers etc you will have unintended side effects. – zsolt Nov 20 '22 at 11:09
  • @zsolt this might be helpful for future reference but it does not help in the current scenario. `docker-compose down src_python_run_28afac65ca0b` closes a container but still restarts a new with with a new id. – bcsta Nov 20 '22 at 16:19
  • @bcsta you current situation is messed up because you fiddled with containers with `docker run/stop` etc commands but they are supposed to be managed by `docker compose` (btw use `docker compose` command that is Compose V2, instead of `docker-compose`). So to make everything clean remove all the stopped containers with `docker rm -f containername` and then retry with using `docker compose` commands. Don't mix compose with "vanilla" container commands, because compose is an abstraction over containers and it will mess up things. – zsolt Nov 20 '22 at 22:10
  • @bcsta One more thing, what you wrote `docker-compose down src_python_run_28afac65ca0b` doesn't really makes sense, because there is no `src_python_run_28afac65ca0b` option for `docker compose down`: [docker compose down docs](https://docs.docker.com/engine/reference/commandline/compose_down/) You issue `docker compose up/down/stop/restart/etc` in the directory where you docker-compose.yaml file is (or if you have different filename you can specify it with -f flag): [docker compose docs](https://docs.docker.com/engine/reference/commandline/compose/) – zsolt Nov 20 '22 at 22:13
  • @bcsta also share your docker-compose.yaml file so we can look at it, maybe you have problems there too. – zsolt Nov 20 '22 at 22:18

1 Answers1

0

In your description, you have a typo unless-stoped -> unless-stopped and in the inspect response the restart params are empty.

Check the documentation of docker run --restart, you are using ¨¨ but this isn't a option: https://docs.docker.com/engine/reference/run/#restart-policies---restart

FedeG
  • 106
  • 6