image.png
操作系統(tǒng)層相關(guān)指令
- 查看版本:
docker -v
[root@localhost ~]# docker -v
Docker version 20.10.6, build 370c289
- 啟動(dòng)docker:
systemctl start docker
- 停止docker:
systemctl stop docker
- 重啟docker:
systemctl restart docker
- 查看docker狀態(tài):
systemctl status docker
- 開機(jī)啟動(dòng):
systemctl enable docker
鏡像操作相關(guān)指令
- 獲取鏡像:
a.docker pull 鏡像名
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest c0cdc95609f1 9 days ago 556MB
centos 7 8652b9f0cb4c 6 months ago 204MB
[root@localhost ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:5122f6204b6a3596e048758cabba3c46b1c937a46b5be6225b835d091b90e46c
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest c0cdc95609f1 9 days ago 556MB
hello-world latest d1165f221234 2 months ago 13.3kB
centos 7 8652b9f0cb4c 6 months ago 204MB
b. docker run
狈癞,該指令會(huì)在鏡像下載完成后創(chuàng)建容器
[root@localhost ~]# docker run -it --name=helloworld hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:5122f6204b6a3596e048758cabba3c46b1c937a46b5be6225b835d091b90e46c
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
- 查看所有鏡像:
docker images
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest c0cdc95609f1 9 days ago 556MB
hello-world latest d1165f221234 2 months ago 13.3kB
centos 7 8652b9f0cb4c 6 months ago 204MB
- 刪除鏡像:
docker rmi
灾搏,如果存在容器伏尼,需要先刪除容器
[root@localhost ~]# docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:5122f6204b6a3596e048758cabba3c46b1c937a46b5be6225b835d091b90e46c
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
Deleted: sha256:f22b99068db93900abe17f7f5e09ec775c2826ecfe9db961fea68293744144bd
容器操作相關(guān)指令
- 創(chuàng)建容器并指定容器名:
docker run -it --name=name image
參數(shù)說(shuō)明(詳情可參考:https://www.runoob.com/docker/docker-run-command.html)
-d (后臺(tái)運(yùn)行容器蚀同,并返回容器ID)
-i (以交互模式運(yùn)行容器,通常與 -t 同時(shí)使用)
--name="nginx-lb" (為容器指定一個(gè)名稱)
-p 宿主機(jī)端口:容器端口(將容器端口綁定主機(jī)端口绣硝,供外部訪問)
docker run -it -p 81:81 --name=centos7-1 centos:7
- 查看所有容器:
docker ps -a
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c9bb239084ae centos:7 "/bin/bash" 11 seconds ago Exited (0) 8 seconds ago centos7-2
fe138210a5b5 centos:7 "/bin/bash" About a minute ago Exited (0) About a minute ago centos7-1
- 查看運(yùn)行中的容器:
docker ps
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c9bb239084ae centos:7 "/bin/bash" 51 seconds ago Up 6 seconds centos7-2
- 運(yùn)行容器:
docker start
[root@localhost ~]# docker start centos7-1
centos7-1
- 停止容器:
docker stop
[root@localhost ~]# docker stop centos7-1
centos7-1
- 刪除容器:
docker rm
,運(yùn)行中的容器無(wú)法刪除,需要先停止
[root@localhost ~]# docker rm centos7-1
centos7-1
- 進(jìn)入容器:
docker attach
勺三,使用exit
退出(會(huì)停止容器)
docker exec -it [CONTAINER ID] bash
,使用exit
退出(不會(huì)停止容器需曾,參數(shù)可參考第一點(diǎn))
[root@localhost ~]# docker attach centos7-2
[root@c9bb239084ae /]# exit
exit
- docker網(wǎng)絡(luò)相關(guān)
# 不指定網(wǎng)絡(luò)驅(qū)動(dòng)時(shí)默認(rèn)創(chuàng)建的bridge網(wǎng)絡(luò)
docker network create simple-network
# 查看網(wǎng)絡(luò)內(nèi)部信息
docker network inspect simple-network
# 查詢網(wǎng)絡(luò)列表
docker network ls
docker inspect bridge
docker inspect my_docker_mysql