[LINUX] How to delete a Docker container

--Environment - CentOS Linux release 7.6.1810 (Core) - Docker Version:18.09.6

Delete the container


$ docker rm {Container ID or container name}

How to delete

#Show all containers, including stopped containers
$ docker ps -a
CONTAINER ID        IMAGE              COMMAND             CREATED             STATUS              PORTS                                              NAMES
dffe12345678        host_delete-target "/usr/sbin/init"    24 hours ago        Up 3 hours          0.0.0.0:18080->8080/tcp, 0.0.0.0:18082->8081/tcp   delete-target
93abcdefghij        host_hoge          "/usr/sbin/init"    4 months ago        Up 3 hours          0.0.0.0:8088->3389/tcp, 0.0.0.0:8089->8080/tcp     hoge

#If it is running, stop it
$ docker-compose stop delete-target
Stopping delete-target ... done

#Let's look at the state again
$ docker ps -a
CONTAINER ID        IMAGE              COMMAND             CREATED             STATUS                        PORTS                                             NAMES
dffe12345678        host_delete-target "/usr/sbin/init"    24 hours ago        Exited (137) 52 seconds ago                                                     delete-target
93abcdefghij        host_hoge          "/usr/sbin/init"    4 months ago        Up 3 hours                    0.0.0.0:8088->3389/tcp, 0.0.0.0:8089->8080/tcp    hoge

#delete
$ docker rm delete-target
delete-target

#Make sure the deleted container is gone
$ docker ps -a
CONTAINER ID        IMAGE                               COMMAND             CREATED             STATUS              PORTS                         NAMES
93abcdefghij        host_hoge       "/usr/sbin/init"    4 months ago        Up 3 hours          0.0.0.0:8088->3389/tcp, 0.0.0.0:8089->8080/tcp    hoge

Stop the container before attempting removal or force remove

$ docker rm dffe12345678
Error response from daemon: You cannot remove a running container dffe... Stop the container before attempting removal or force remove

--Cause: The container has not been stopped --Action: Stop the container and then delete it

Can't find a suitable configuration file in this directory or any parent.

$ docker-compose stop delete-target
ERROR:
        Can't find a suitable configuration file in this directory or any
        parent. Are you in the right directory?

        Supported filenames: docker-compose.yml, docker-compose.yaml

--Cause: Because you operate in a directory without docker-compose.yml --Action: Operate in the directory containing the docker-compose.yml to be deleted

Recommended Posts

How to delete a Docker container
Carry a Docker container
How to delete log with Docker, not to collect log
How to make a container name a subdomain and make it accessible in Docker
How to call a function
How to hack a terminal
How to Delete with SQLAlchemy?
How to hold a hands-on seminar using Jupyter using docker
How to build a Django (python) environment on docker
How to run a Django application on a Docker container (development and production environment)
How to make a Japanese-English translation
How to write a Python class
[Ubuntu] How to delete the entire contents of a directory
How to put a symbolic link
How to make a slack bot
How to create a Conda package
How to make a crawler --Advanced
How to create a virtual bridge
How to create / delete symbolic links
Run Matplotlib on a Docker container
How to implement Python EXE for Windows in Docker container
How to make a deadman's switch
How to create a Dockerfile (basic)
[Blender] How to make a Blender plugin
How to write Docker base image
How to make a crawler --Basic
How to create a config file
How to log in to Docker + NGINX
How to delete multiple specified positions (indexes) in a Python list
Learn how to use Docker through building a Django + MySQL environment
How to create a clone from Github
How to split and save a DataFrame
How to create a git clone folder
Qiita (1) How to write a code name
How to add a package with PyCharm
[Python] How to make a class iterable
[Python] How to convert a 2D list to a 1D list
How to create an NVIDIA Docker environment
How to delete expired sessions in Django
[Colab] How to copy a huge dataset
[Python] How to invert a character string
How to install a package using a repository
[Ubuntu] How to execute a shell script
How to get a stacktrace in python
How to use tensorflow under docker environment
How to create a repository from media
How to make a Backtrader custom indicator
How to choose a Seaborn color palette
How to test on a Django-authenticated page
How to make a Pelican site map
Run matplotlib on a Windows Docker container
How to run a Maya Python script
How to install python3 with docker centos
I made a Docker container to use JUMAN ++, KNP, python (for pyKNP).
Reintroduction to Docker
How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code
How to selectively delete past tweets with Tweepy
How to make a dialogue system dedicated to beginners
How to calculate the volatility of a brand
How to read a CSV file with Python 2/3
How to disguise a ZIP file as a PNG file