LoginSignup
3
1

More than 3 years have passed since last update.

Dockerでubuntuイメージを取得してきてコンテナ起動する

Last updated at Posted at 2020-07-22

https://hub.docker.com/_/ubuntu を起動する時のコマンドメモ。
ふとlinuxコマンドを動かしたくなった時にさっと使えるようにメモです。

イメージの取得

docker pull ubuntu

コンテナをバックグラウンドで起動

docker run --name <container_name> -it -d <image_name> /bin/bash
# 例
docker run --name ubuntu -it -d ubuntu /bin/bash

シェルに入る

docker exec -it <container_name> /bin/bash
# 例
docker exec -it ubuntu /bin/bash

おまけ

コンテナ名をつけ忘れたり間違えてしまったら

docker rename でコンテナ名を変更できる。

docker rename <current_name> <new_name>

manを使いたい

シェル内からman読もうと思ったらミニマムな構成とのことでそのままだと使えなかった(コンテナってこういうものだよね…)

root@10b70c6ce5aa:/# man mount
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, including manpages, you can run the 'unminimize'
command. You will still need to ensure the 'man-db' package is installed.

unminimize 叩いてみた

root@10b70c6ce5aa:/# unminimize
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
<snip>

2回くらい[y/n]聞かれるので Y 押す

リトライ

root@10b70c6ce5aa:/# man mount
bash: /usr/bin/man: No such file or directory

そもそもいなかった(コンテナってこういうものd)

更新&インストール(いつもの)

root@10b70c6ce5aa:/# apt update
root@10b70c6ce5aa:/# apt install -y man

パッケージ一覧確認

root@10b70c6ce5aa:/# dpkg -l | grep man
<snip>
ii  man-db                  2.9.1-1                 amd64        tools for reading manual pages
<snip>

man-db が増えた

root@10b70c6ce5aa:/# man mount

今度はman見れるようになりました!

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