2022年3月17日 星期四

Docker/Container基本操作

 

先切換到 root

1. 安裝 yum-utils

yum install -y yum-utils device-mapper-persistent-data lvm2


2. 設定 repository

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo


3. 安裝 Docker CE

yum install docker-ce

出現error

打開 etc/yum.repos.d/docker-ce.repo

將 $releasever全部改7

例如

baseurl=https://download.docker.com/linux/centos/$releasever/source/stable

改成

baseurl=https://download.docker.com/linux/centos/7/source/stable

重新輸入

yum install docker-ce

檢查docker版本

docker version

4. 啟動 Docker

systemctl start docker

5. 測試 Docker

docker run hello-world

6. 設定開機自動啟動 Docker

systemctl enable docker

停止

systemctl stop docker

重啟

systemctl restart docker

狀態

systemctl status docker


7. 錯誤處理

重開機後遇到

Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?

解答

You can try out this: 

systemctl start docker

It worked fine for me.


P.S.: after if there is commands that you can't do without sudo, try this:

gpasswd -a $USER docker

8. 下載、執行Image

docker pull centos

上面那行會抓到centos 8
如果要指定版本7.9

docker pull centos:centos7.9.2009

列出 image list

docker image ls

執行

docker run -it centos:centos7.9.2009 bash

印出目前執行版本

cat /etc/*release










沒有留言:

張貼留言