0
0

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のrestart→exec→exitではexitedしない話

Last updated at Posted at 2020-08-02

dockerを勉強し始めて、exitしたのにexitedにならなくハマったお話。

##開始前のコンテナの状態
$docker ps -aでコンテナの状況を確認。

$docker ps -a 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES
b45e56cec3c6        ubuntu              "bash"              7 hours ago         Exited (137) 17 minutes ago                       silly_hoover
c71eae7ff038        hello-world         "/hello"            7 hours ago         Exited (0) 7 hours ago                            elegant_swanson
6374f67a1248        hello-world         "/hello"            7 hours ago         Exited (0) 7 hours ago                            epic_varahamihira

今回はCONTAINER ID:b45e56cec3c6を起動する。

##コンテナ起動
$docker restart b45e56cec3c6で起動してみる。

$docker ps -a               
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES
b45e56cec3c6        ubuntu              "bash"              7 hours ago         Up 1 second                                  silly_hoover
c71eae7ff038        hello-world         "/hello"            7 hours ago         Exited (0) 7 hours ago                       elegant_swanson
6374f67a1248        hello-world         "/hello"            7 hours ago         Exited (0) 7 hours ago                       epic_varahamihira

起動した。

ubuntuの中へ

$docker exec -it b45e56cec3c6 bashでbash実行。

$docker exec -it b45e56cec3c6 bash  
root@b45e56cec3c6:/# 

入った。

##コンテナを抜ける
$exitでコンテナを抜けホストに戻る。

root@b45e56cec3c6:/# exit
exit

戻ってきたので、コンテナのステータスを確認。

##ステータス
$docker ps -aで確認

$docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES
b45e56cec3c6        ubuntu              "bash"              7 hours ago         Up 4 minutes                                 silly_hoover
c71eae7ff038        hello-world         "/hello"            7 hours ago         Exited (0) 7 hours ago                       elegant_swanson
6374f67a1248        hello-world         "/hello"            7 hours ago         Exited (0) 7 hours ago                       epic_varahamihira

exitedになっていない。。。

##アタッチしてみる
$docker attach b45e56cec3c6

docker attach b45e56cec3c6
root@b45e56cec3c6:/# 

入れた。

##再度exit
$exitを再度実行。

$exit
exit

##再度ステータスを確認
$docker ps -aを再度実行。

$docker ps -a                     
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
b45e56cec3c6        ubuntu              "bash"              7 hours ago         Exited (0) 41 seconds ago                       silly_hoover
c71eae7ff038        hello-world         "/hello"            7 hours ago         Exited (0) 7 hours ago                          elegant_swanson
6374f67a1248        hello-world         "/hello"            7 hours ago         Exited (0) 7 hours ago                          epic_varahamihira

無事exitedになってる!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?