docker already have container running - docker

When I launch docker, it launch by default a few containers that I have build in the past.(I've use docker-compose at the time, but deleted the repo since)
I kill them, but each time i restart docker, they are back.
What can I do ?
I know there is something like "docker system prune",
but I would like to delete the less possible .

You can try running docker ps -a to get a list of all containers including the ones which are not running but stopped.
You can then docker rm each container you do not wish to start on each docker restart.

Use docker ps to see what containers are running.
Use this command to kill/stop all running containers.
docker rm $(docker ps -a -q)
Use docker images to get list of all images.
Use docker rmi <image_id> to delete desired image.

Related

stop and delete running containers

I installed from here a simple training application https://github.com/dockersamples/example-voting-app
After that i want to remove working containers and then images of this app. I`m trying type this:
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rm -f *containers*
First everything is deleted, but then the containers are restarted and recreated automatically even though I deleted this folder from the computer with the application.
And have this error
Error response from daemon: You cannot remove a running container
Probably autostart is registered in docker-compose-files, but I already deleted the folder with this project from my mac
Every time i have 3 this running containers :
dockersamples/visualizer:stable "npm start" vote_vis
dockersamples/examplevotingapp_result:before "node server.vote_res
postgres:9.4 "docker-entry vote_db.
How can i fix it and delete everything?
You probably have the containers running in swarm mode. When you stop or delete a container, swarm mode will see the difference from the target state and redeploy containers to get you to the target state. To stop and delete containers started by swarm mode, you need to run stack and service commands instead:
docker stack rm $(docker stack ls --format '{{.Name}}')
Give that a minute to complete, then for any services not managed as a stack, you can run:
docker service rm $(docker service ls -q)

How do I kill the docker processes?

I have tried
docker kill name_of_the_process
But the error is
Error response from daemon: Cannot kill container: name_of_the_container: Container name_of_the_container is not running
There are a lot of processes when I run docker ps -a, how do I kill those, they are stopped but not killed
A stopped container is killed. There is no running process, but there is a writable container specific filesystem and some metadata remaining which allows you to debug the stopped container and restart it. To remove that, use docker container rm (or the former alias docker rm) to remove the stopped container data. e.g.
docker container ls -aqf status=exited | xargs docker container rm
docker ps Shows you the running containers. If you add the -a flag it will print out all the containers, even the ones not running.
You can not "stop" a non-running container, it is already stopped.
You can find more information here: https://docs.docker.com/engine/reference/commandline/ps/
If you wish to remove the container, you can remove it by id or name. The command for that is docker rm <id/name>
Tip: You can use the first few chars of the id to identify the container, you don't need the whole id

exit and delete all but the latest docker container

I currently have a lot of docker containers running that are no longer used.
So many actually that it would take a while to exit and quit them all manually.
I was wondering if there was a way to exit and delete all of them except for the latest one ?
A quick approach to do this is the following:
First, stop all containers with this command:
docker stop $(docker ps -aq)
Then, start the container that you want to keep using:
docker start container_name
And finally, use docker container prune, which removes all stopped containers.
docker container prune

Docker - Cannot connect to the Docker Daemon to rm containers

Playing with ELK and docker, I needed to restart every services.
docker ps told me that I haven't any containers up.
docker run -it --rm [...] --name es elasticsearch -> Error response from daemon. The name "es" is already use by container [...]
So I try to remove all container :
docker ps -a -q | xargs docker rm -> Cannot connect to the Docker daemon. Is the docker daemon running on this host?
The container is not up but still here.
Of course I can simply change my container's name but it's not right. That mean I have container running. Even if I restart my server.
Any idea ?
When you stop your container it's not getting removed by default, unless you're providing --rm flag. So, it could be so, like you have started and stopped some container with es name before and it's stopped now. But it's not possible to create a new container with the existing name, even if the existing one is not running. Try to use a -a flag to show all containers you have as:
docker ps -a
If you have some with the name es, just remove it manually with:
docker rm es
You also able to provide -f flag, to force removing the es container even if it's running.
docker rm es should do the trick. Furthermore, if you want to remove a running container, you can add the -f parameter(docker rm -f 'container_name')

Can I restart a docker container listed in the docker ps -a output?

The first time I ran my configured image, I passed in a --name option. After running the image, I stopped it. Now, it appears in the docker ps output:
vagrant#precise64:~/docker$ docker ps -a
Since it has a name, how can I restart it? It seems that the docker run command only accepts an imageid (not a containerid). And if run it again, a new container is created (which is not what I want).
To start a stopped container one could issue
docker start {name}

Resources