Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove file from stopped docker container (without create new image) [duplicate]

Tags:

docker

I have simple container with some service.

When I restarting server without stopping this container, I can't start it again.

Error message is:

pidfile found, try stopping another running service or delete /var/run/service.pid

I know that I can

  1. run new container from image and delete stopped one
  2. create new image from stopped container and re-run it with new entrypoint. Something like rm -f /var/run/service.pid && original_entrypoint.sh

But I want simply do something like

docker rm_file container:/var/run/service.pid; docker start container

Because it is most simple and fast to start solution.

Isn't here is no way to access container's fs without completely rebuild it? This operation is looking so useful...

like image 309
rzlvmp Avatar asked Nov 04 '25 16:11

rzlvmp


1 Answers

Answering by myself using hints from another answer

  1. Find where directory stored on docker host:

    export LOCAL_DIR=$(docker inspect -f '{{ .GraphDriver.Data.UpperDir }}' container_name)
    
  2. Remove file locally:

    sudo rm -f ${LOCAL_DIR}/run/service.pid
    
  3. Run container:

    docker start container_name
    

Or all in one:

sudo rm -f "$(docker inspect -f '{{ .GraphDriver.Data.UpperDir }}' container_name)/run/service.pid" && docker start container_name
like image 155
rzlvmp Avatar answered Nov 07 '25 09:11

rzlvmp