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 5 years have passed since last update.

Docker Cheet Sheet(メモ)

Posted at

さっと書いただけなんで適宜変更していきます。

Docker の導入(Ubuntu版)

sudo apt-get update
wget -qO- https://get.docker.com/ | sh

Docker imageの検索

sudo docker search <調べたいosとか> | more

Docker imageを引っ張ってくる
sudo docker pull <調べたやつ>

imageの確認

sudo docker images
//Image IDがImageの実態となる。

Imageの設定の確認

sudo docker inspect <名前+TAG>or<ID>

Imageの削除

sudo docker rmi <名前+TAG>or<ID>

コンテナの実行

sudo docker run <名前> <実行したいコマンド> (e.g. echo "hello world")

実行中のコンテナの確認

sudo docker ps

実行後も含めたコンテナの確認

sudo docker ps -a (<-n=数>で数を指定できる)

コンテナの削除

sudo docker rm <ID>

継続的にコンテナの実行

sudo docker run -d <imageの名前> free -s 3
//-dはバックグラウンドで走らせる
//freeはメモリの状況を見る
//3は3秒ごとに走らせる

実行中のタスクのログの確認

sudo docker logs

タスクを前面に出す

sudo docker attach --sig-proxy=false <ID>

実行中のコンテナを止める

sudo docker stop (or kill) <ID>

実行中のコンテナを進める

sudo docker start <ID>

コンテナの中で作業をする方法

sudo docker run -i -t <image> /bin/bash
//-i インタラクティブモード=コンテナの中に
//-t ターミナルを立ち上げる

imageの作成

sudo docker commit <ID> <Imageの名前 e.g. kota/<sth>>

Dockerfileについて(Dockerfileの編集)

Dockerfile (例)
From <image>
MAINTAINER <name><address>
//RUN <sth> (e.g. RUN echo "now building...")
//CMD[<sth>](e.g. CMD["echo","now running"];
RUN yum install -y httpd
ADD ./index.html /var/www/html
EXPOSE 80
CMD["/usr/bin/httpd", "-D", "FOREGROUND"]

→index.htmlを作る

sudo docker build -t <新しいimageの名前>

sudo docker run <image>

docker hubにログイン

sudo docker login

imageのpush

sudo docker push <imageの名前>

参考

http://docs.docker.com/linux/step_one/
http://dotinstall.com/lessons/basic_docker

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?