docker container not removing from docker - docker

I am trying to remove container but when i run docker-compose rm ,runs fine but when i run docker ps then again it shows container:
root#datafinance:/tmp# docker-compose rm
Going to remove tmp_zookeeper_1_31dd890a1cbf
Are you sure? [yN] y
Removing tmp_zookeeper_1_31dd890a1cbf ... done
root#datafinance:/tmp# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
03b08e4ef0b3 confluentinc/cp-zookeeper:latest "/etc/confluent/dock…" 14 hours ago Up 14 hours docker_c_zookeeper_1_7c953dce7d69

Use docker-compose ps, it will show the container which only launched by docker-compose up. If it shows there is no container, then this means this container was not launched by this docker-compose.yaml.
And Error starting userland proxy: listen tcp 0.0.0.0:32181: bind: address already in use' means the port 32181 is occupied either by other docker container or other process. You could use docker rm -f $(docker ps -qa) to delete all containers or more you can use netstat -oanltp | grep 32181 to find which process really occupy 32181.
Finally, if for any reason you did not able to delete container as you said, you can just use service docker restart or systemctl restart docker to make all container down. Then repeat above docker rm xxx.
With above steps, you can use docker compose up -d to use your service now.

try this :
docker rm -f 03b08e4ef0b3
DANGER
you may also try this, but be aware that will delete everything (Containers, Images, Networks, ....)
docker system prune -a -f
when all not helped your last resort is to restart Docker daemon
service docker restart
and then repeat the steps...

I think what you are looking for is :
docker-compose down
which removes the containers after stopping them according to this.
According to this, docker-compose rm removes the "stopped" containers. If your container(s) are running, I think it won't remove to prevent accidents.

Related

docker already have container running

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.

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 to kill container generated by docker-compose?

(sorry using the term "kill" with quotes is not about docker-compose kill, is about "UNIX ps kill" after what the process really go out of the "UNIX ps list")
Usual docker run can be "killed" by usual docker stop, because after stop I not see the container at docker ps -a... If it is correct, there are a semantic bug with docker-compose because I can't "kill" the containers, they stay at docker ps.
After my simple docker-compose up (without &) I do ^C and the containers stay there at docker ps -a... Impossible to kill by docker compose stop.
NOTE: when I use ordinary docker run and after it docker stop there are nothing at docker ps -a, so I can say "I killed it".
Usual docker run can be "killed" by usual docker stop, because after stop I not see the container at docker ps.
No. docker stop just stops a running container, it doesn' t remove the container. This happens only in case you've used docker run --rm .... This --rm option means that when the container is stopped, it will be removed/deleted.
Docker
docker run ... creates and runs a container
docker stop ... stops a running container
docker start ... starts a stopped container
docker rm ... removes a stopped container
Docker Compose
docker-compose up creates and runs a collection of containers
docker-compose stop stops the containers
docker-compose start starts the containers
docker-compose down stops and removes the containers
Be careful...
As it discussed in the comments section, by using docker-compose down other things can also take place regarding volumes, networks. Keep in mind that you might lose data (if your container is a database for example) and make sure you have saved them or you are somehow able to create them again.
Check out running containers:
docker ps
Example output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e86521d81a96 app_php "docker-php-entrypoi…" 2 hours ago Up About an hour 0.0.0.0:8080->80/tcp app_php_1
7a30681b6255 mysql:5.6 "docker-entrypoint.s…" 3 hours ago Up About an hour 0.0.0.0:3306->3306/tcp app_db_1
21aa3eef5f42 phpmyadmin/phpmyadmin "/run.sh supervisord…" 4 hours ago Up About an hour 9000/tcp, 0.0.0.0:8081->80/tcp app_phpmyadmin_1
9afc52b3f82f mailhog/mailhog "MailHog" 4 hours ago Up About an hour 1025/tcp, 0.0.0.0:8082->8025/tcp app_mailhog_1
then stop one by the container id:
docker kill part_of_the_id/name
For instance:
docker kill e86 or docker kill app_php_1
Docker-compose is just a script to help you manage one or multiple containers running in a group and is absolutely not required to manage your containers.
To remove the container completely you have to remove the container docker rm container_id_or_name
To stop all running containers:
docker stop $(docker ps -q)
You can use docker rm <container-name> to do that. This command will stop and remove service container. Anonymous volumes attached to the container will not be removed.

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')

Docker - Name is already in use by container

Running the docker registry with below command always throws an error:
dev:tmp me$ docker run \
-d --name registry-v1 \
-e SETTINGS_FLAVOR=local \
-e STORAGE_PATH=/registry \
-e SEARCH_BACKEND=sqlalchemy \
-e LOGLEVEL=DEBUG \
-p 5000:5000 \
registry:0.9.1
Error response from daemon: Conflict. The name "registry-v1" is already in use by container f9e5798a82e0. You have to delete (or rename) that container to be able to reuse that name.
How can I prevent this error ?
I got confused by this also. There are two commands relevant here:
docker run # Run a command in a **new** container
docker start # Start one or more stopped containers
That means you have already started a container in the past with the parameter
docker run --name registry-v1 ...
You need to delete that first before you can re-create a container with the same name with
docker rm registry-v1
When that container is sill running you need to stop it first before you can delete it with
docker stop registry-v1
Or simply choose a different name for the new container.
To get a list of existing containers and their names simply invoke
docker ps -a
Here what i did, it works fine.
step 1:(it lists docker container with its name)
docker ps -a
step 2:
docker rm name_of_the_docker_container
When you are building a new image you often want to run a new container each time and with the same name. I found the easiest way was to start the container with the --rm option:
--rm Automatically remove the container when it exits
e.g.
docker run --name my-micro-service --rm <image>
Sadly it's used almost randomly in the examples from the docs
Edit: Read Lepe's comment below.
Just to explain what others are saying (it took me some time to understand) is that, simply put, when you see this error, it means you already have a container and what you have to do is run it. While intuitively docker run is supposed to run it, it doesn't. The command docker run is used to only START a container for the very first time. To run an existing container what you need is docker start $container-name. So much for asking developers to create meaningful/intuitive commands.
You have 2 options to fix this...
Remove previous container using that name, with the command docker rm $(docker ps -aq --filter name=myContainerName)
OR
Rename current container to a different name i.e change this portion --name registry-v1 to something like --name myAnotherContainerName
You are getting this error because that container name ( i.e registry-v1) was used by another container in the past...even though that container may have exited i.e (currently not in use).
Cause
A container with the same name is still existing.
Solution
To reuse the same container name, delete the existing container by:
docker rm <container name>
Explanation
Containers can exist in following states, during which the container name can't be used for another container:
created
restarting
running
paused
exited
dead
You can see containers in running state by using :
docker ps
To show containers in all states and find out if a container name is taken, use:
docker ps -a
Here is how I solved this on ubuntu 18:
$ sudo docker ps -a
copy the container ID
For each container do:
$ sudo docker stop container_ID
$ sudo docker rm container_ID
removing all the exited containers
docker rm $(docker ps -a -f status=exited -q)
The Problem: you trying to create new container while in background container with same name is running and this situation causes conflicts.
The error would be like:
Cannot create continer for service X :Conflict. The name X is already in use by container abc123xyz. You have to remove ot delete (or rename) that container to be able to reuse that name.
Solution rename the service name in docker-compose.yml or delete the running container and rebuild it again (this solution related to Unix/Linux/macOS systems):
get all running containers sudo docker ps -a
get the specific container id
stop and remove the duplicated container / force remove it
sudo docker stop <container_id>
sudo docker rm <container_id>
or
sudo docker rm --force <container_id>
You can remove it with command sudo docker rm YOUR_CONTAINER_ID, then run a new container with sudo docker run ...;
or restart an existing container with sudo docker start YOUR_CONTAINER_ID
I was running into this issue that when I run docker rm (which usually works) I would get:
Error: No such image
The easiest solution to this is removing all stopped containers by running:
docker container prune
I have solved the issue by doing following steps and I hope it helps.
Type docker ps -a to list all the containers in your system.
Check the NAMES part where you have initialized your docker container.
Then type docker rm --force name_of_container
Install the docker container as you wish.
I had problem using NIFI and I have removed and reinstalled using docker. Good luck.
TL:DR;
List all containers:
docker ps -a
Remove the concerned container by id:
docker container rm <container_id>
The OP's problem is the error. Deleting state isn't the only solution - or even a good one. The problem is docker run isn't re-entrant, and docker start is impotent w/o run. So we have to combine them.
For example to run Postgres w/o destroying previous state, try this:
docker start postgres || docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=password postgres:13-alpine
I'm just learning docker and this got me as well. I stopped the container with that name already and therefore I thought I could run a new container with that name.
Not the case. Just because the container is stopped, doesn't mean it can't be started again, and it keeps all the same parameters that it was created with (including the name).
when I ran docker ps -a that's when I saw all the dummy test containers I created while I was playing around.
No problem, since I don't want those any more I just did docker rm containername at which point my new container was allowed to run with the old name.
Ah, and now that I finish writing this answer, I see Slawosz's comment on Walt Howard's answer above suggesting the use of docker ps -a
Ok, so I didn't understand either, then I left my pc, went to do other things, and upon my return, it clicked :D
You download a docker image file. docker pull *image-name* will just pull the image from docker hub without running it.
Now, you use docker run, and give it a name (e.g. newWebServer).
docker run -d -p 8080:8080 -v volume --name newWebServer image-name/version
You perhaps only need docker run --name *name* *image*, but the other stuff will become useful quickly.
-d (detached) - means the container will exit when the root process used to run the container exits.
-p (port) - specify the container port and the host port. Kind of the internal and external port. The internal one being the port the container uses, and the external one is the port you use outside of it and probably the one you need to put in your web browser if that's how you access your app.
--name (what you want to call this instance of the container) - you could have several instances of the same container all with different names, which is useful when you're trying to test something.
image-name/version is the actual image you want to create the container from. You can see a list of all the images on your system with docker images -a. You may have more than one version, so make sure you choose the correct one/tag.
-v (volume) - perhaps not needed initially, but soon you'll want to persist data after your container exits.
OK. So now, docker run just created a container from your image. If it isn't running, you can now start it with it's name:
docker start newWebServer
You can check all your containers (they may or may not be running) with
docker ps -a
You can stop and start them (or pause them) with their name or the container id (or just the first few characters of it) from the CONTAINER ID column e.g:
docker stop newWebServer
docker start c3028a89462c
And list all your images, with
docker images -a
In a nutshell, download an image; docker run creates a container from it; start it with docker start (name or container id); stop it with docker stop (name or container id).
I had this issue because I had two or more containers with the same container_name in the docker-compose.yml file.
Simple Solution: Goto your docker folder in the system and delete .raw file or docker archive with large size.
For me, the issue was that I used an image name more than once in the dockerfile.
This happened to me on the docker tutorial! The port I tried to use was taken, but docker still created.. an image? A process to run docker? I'll find out soon. Anyways, to choose a different port, I had to remove the older image, and then docker run again.
Sometimes a tutorial can be too terse. What you want is concise, not terse, or even succinct.

Resources