Skip to content

Instantly share code, notes, and snippets.

@hagix9
Last active January 24, 2024 10:12
Show Gist options
  • Save hagix9/7287293 to your computer and use it in GitHub Desktop.
Save hagix9/7287293 to your computer and use it in GitHub Desktop.
Dockerのコマンド
#ビルド
docker build -t "sshd/centos" .
#コンテナを起動
docker run -i -t centos /bin/bash
#コンテナに名前を付けて起動
docker run -i -t --name cent01 centos /bin/bash
#コンテナをバックグランドで起動
docker run -i -t -d centos /bin/bash
#外部ポート、内部ポートを指定しコンテナをバックグランドで起動
docker run -t -i -d -p 11111:22 -p 22222:80 sshd/centos
#コンテナを削除
docker rm sshd/centos
docer rm $(docker ps -a -q)
#コンテナ起動イメージ削除
docker rmi sshd/centos
#ホストのディレクトリをマウントしてコンテナを起動
docker run -v /hos_tdir:/opt/cnt_dir -i -t centos /bin/bash
#コンテナ内からデタッチ
ctrl-p ctrl-q
#コンテナをコミット
docker run -i -t -d --name cent01 centos /bin/bash
docker commit cent01 test1/centos
#コミットしたコンテナで別のコンテナを起動
docker run -i -t -d --name cent02 test1/centos /bin/bash
#コンテナをエクスポート
#名前orIDを指定
docker export cent01 > cent01.tar
#URLを指定してインポート(imageに登録される)
docker import http://hoge.com/cent01.tar cent01
#ローカルファイルを指定してインポート(imageに登録される)
cat cent01.tar | docker import - cent01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment