20
17

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.

wsl2でDocker自動起動設定

Last updated at Posted at 2020-10-10

wsl2を使ってみて、Dockerを自動起動設定ができないらしく、
毎回 serviceコマンドを打つのが面倒なので検討してみた

ユーザでパスワード無しで起動できるようにsudoに設定

$ sudo visudo
# docker deamon auto up
ユーザ ALL=(ALL:ALL) NOPASSWD: /usr/sbin/service docker start
停止時
$ service docker status
 * Docker is not running
起動時
$ service docker status
 * Docker is running

.bashrcにdockerが起動していないときだけ、スタートさせるように追記

$vim .bashrc
#追記
echo $(service docker status | awk '{print $4}') #起動状態を表示
if test $(service docker status | awk '{print $4}') = 'not'; then #停止状態
        sudo /usr/sbin/service docker start #起動
fi

この設定で、wsl2に入るときに、Dockerが停止していたら起動するようになりました。
image.png

20
17
1

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
20
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?