dockerも大分馴染んできたので,簡単な概要と,よく使うコマンドのリスト,使い方,オプション,簡単な例を書き留めておく.
Dockerの概要
簡単に壊せる環境が作れる優れもの.
例として,得体の知れないコードを実行したり,データのクラッキングが前提のコードを実行したりということが容易にできる.
Gitのスターの少ないライブラリを試したい時や,ホストに入れる前に動作を確認したい/ホストで不具合でたのでセーフモード的に検証したい,など.
dockerの上にimage(ubuntu/ruby etc)があって,そのimageからContainerを作る.ContainerはubuntuなどのOSからrubyなど単純な実行環境まで様々.
imageの作り方として,docker hubからpull
するか,Dockerfileを作成し,docker build .
する方法がある.
しかしながらwindowsだとマウントやその他多点においてLinuxとの相違が点在する.
dockerコマンドをpowershellから実行することは通常できなく,docker tool boxの専用シェルでのみ実行可能.
Commands:
-
attach Attach to a running container
docker attach
起動しているコンテナに接続する.参考: start, ps
-
build Build an image from a Dockerfile
カレントディレクトリのDockerfileをビルドしてimageを作成する.
docker build .
docker build -f /path/to/a/Dockerfile .
docker build -t shykes/myapp . -
commit Create a new image from a container’s changes
コンテナの状態からイメージを作る.
-
cp Copy files/folders between a container and the local filesystem
ローカルとコンテナ間でファイルのやり取り.
カレントディレクトリのファイルをコンテナに渡す.
docker cp .:/usr/local/bin コンテナのファイルをローカルにコピー.
docker cp:/usr/local/bin ../dest/ -
create Create a new container
-
diff Inspect changes to files or directories on a container’s filesystem
docker diff
container間の差異ではない.commitもできないようで,あまり使わなそう. -
events Get real time events from the server
-
exec Run a command in a running container
コマンドを実行して終了.
docker exec
ls /usr/local/bin
docker execruby -v インタラクティブに実行.
docker exec -iirb -
export Export a container’s filesystem as a tar archive
-
history Show the history of an image
docker history
-
images List images
docker images -a
-
import Import the contents from a tarball to create a filesystem image
-
info Display system-wide information
docker info
-
inspect Return low-level information on Docker objects
-
kill Kill one or more running containers
コンテナの強制終了.
-
load Load an image from a tar archive or STDIN
.tar圧縮されたイメージからイメージを作成.
-
login Log in to a Docker registry
- logout Log out from a Docker registry
-
logs Fetch the logs of a container
実行コマンドのログ.
docker logs -
pause Pause all processes within one or more containers
- port List port mappings or a specific mapping for the container
-
ps List containers
docker ps
docker ps -a -
pull Pull an image or a repository from a registry
docker imagesのレジストリからイメージを取得.
docker pull python参考: serach
-
push Push an image or a repository to a registry
レジストリにイメージを公開する場合.
-
rename Rename a container
docker rename
docker ps で表示されるNAMES
の変更. -
restart Restart one or more containers
コンテナを再起動.
-
rm Remove one or more containers
コンテナを削除.
全てのコンテナを削除する
docker rm $(docker ps -aq) -
rmi Remove one or more images
イメージを削除.
全てのイメージを削除
docker rmi $(docker images -aq) -
run Run a command in a new container
docker run -it
docker run –rm -it -p 1000:1000 -v //c/docker:/dockerls /docker
docker run –rm -it -v //c/Users/$USERNAME/src:/docker ubuntu ls /docker
docker run –privileged -it –rm –name swift swift -
save Save one or more images to a tar archive (streamed to STDOUT by default)
イメージを.tar圧縮.
-
search Search the Docker Hub for images
imageが公式か非公式か,どれだけ利用されているか分かる.
docker serach python -
start Start one or more stopped containers
stopしているコンテナを起動.-aiで接続.
docker start -ai -
stats Display a live stream of container(s) resource usage statistics
コンテナごとのcpu/メモリ情報などを表示する.
docker stats -a -
stop Stop one or more running containers
コンテナの停止.
docker stop全てのコンテナを停止する
docker stop $(docker ps -aq) -
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
docker images
で表示されるイメージ名/TAGを変更する
docker math:latest math:1.0 -
top Display the running processes of a container
docker top
-
unpause Unpause all processes within one or more containers
- update Update configuration of one or more containers
-
version Show the Docker version information
docker version
-
wait Block until one or more containers stop, then print their exit codes