1
1

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 1 year has passed since last update.

[覚書]Dockerコンテナ上のUbuntuでsudoコマンドが使いたい

Last updated at Posted at 2022-04-22

経緯

Dockerコンテナを仮想環境として使おうと思いsudoコマンドを使おうとしたら怒られたので解決法をメモしておく.

CMD
root@hogehoge $ sudo
bash: sudo:command not found

解決

CMD
root@hogehoge $ apt-get update

root@hogehoge $ apt-get -y install sudo

root@hogehoge $ sudo
usage: sudo -h | -K | -k | -V
...

これで使えるようになりました. やったぁ

おまけ

Dockerfileも作ってみたけど

Dockerfile
FROM ubuntu:12.04

RUN apt-get update && apt-get install -y sudo

USER docker
CMD /bin/bash

これだとなぜかエラーが出る.

...> Docker build <filepath>
(中略)
-----
executor failed running [/bin/sh -c apt-get update && apt-get install -y sudo]: exit code: 100

毎回手作業でインストールするのは面倒くさいのでイメージ化したかったけどできなかったとさ.

参考にしたサイト

How to use sudo inside a docker container?

小言

なんでデフォルトで使えないんですか???

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?