2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dockerのコンテナを削除する方法

Posted at
  • 環境
    • CentOS Linux release 7.6.1810 (Core)
    • Docker Version:18.09.6
コンテナを削除する
$ docker rm {コンテナID or コンテナ名}

削除する方法

# 停止しているコンテナを含めて全コンテナを表示する
$ 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

# 起動していたら停止する
$ docker-compose stop delete-target
Stopping delete-target ... done

# もう一回状態を見ておく
$ 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

# 削除する
$ docker rm delete-target
delete-target

# 削除したコンテナがいなくなったことを確認する
$ 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
  • 原因 : コンテナを停止していないから
  • 対応 : コンテナを停止してから削除する

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
  • 原因 : docker-compose.ymlのないディレクトリで操作するから
  • 対応 : 削除対象のdocker-compose.ymlのあるディレクトリで操作する
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?