インストール
dockerとdocker-composeをインストールする一連のコマンド
USERNAME=#ユーザ名
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
sudo echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
sudo gpasswd -a $USERNAME docker
sudo mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL https://github.com/docker/compose/releases/download/v2.15.0/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
sudo ln -s /usr/local/lib/docker/cli-plugins/docker-compose /usr/bin/docker-compose
この後再起動が必要
動作確認
sudo service docker start
docker run hello-world
自動起動設定
以下を実行して編集画面へ
sudo visudo
末尾に以下を追加して保存
%docker ALL=(ALL) NOPASSWD: /usr/sbin/service docker start
~/.bashrcの末尾に以下を追記して保存
if [ $(service docker status | awk '{print $4}') = "not" ]; then
sudo service docker start > /dev/null
fi