docker的基础操作

1.安装docker服务,配置镜像加速器

# step 1: 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新并安装Docker-CE
yum makecache fast
yum -y install docker-ce
# Step 4: 开启Docker服务
service docker start
# Step 5: 配置镜像加速器
[root@localhost ~]# cd /etc/docker/
[root@localhost docker]# ls
certs.d daemon.json seccomp.json
[root@localhost docker]# tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://rvq9mjyt.mirror.aliyuncs.com"]
}
EOF
[root@localhost docker]# systemctl daemon-reload
[root@localhost docker]# systemctl restart docker

2.下载系统镜像(Ubuntu、 centos)

latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete 
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@localhost ~]# docker images 
REPOSITORY   TAG           IMAGE ID       CREATED         SIZE
ubuntu       latest        ba6acccedd29   22 months ago   72.8MB
centos       latest        5d0da3dc9764   23 months ago   231MB

3.基于下载的镜像创建两个容器 

[root@localhost ~]# docker run --name test2 -dit centos:latest /bin/bash
f1e29cbd17db1131e46139e36a6d21b3179775caecb94558e73650dd0171dad0
[root@localhost ~]# docker run --name test1 -dit ubuntu:latest /bin/bash
dd77e4455f767bf7ef76340621bc675ba7a3e4653c5941af20f499b862d5325a

4.容器的启动、 停止及重启操作

[root@localhost ~]# docker start test1
test1
[root@localhost ~]# docker start test2
test2
[root@localhost ~]# docker stop test1
test1
[root@localhost ~]# docker stop test2
test2
[root@localhost ~]# docker restart test1
test1
[root@localhost ~]# docker restart test2
test2

5.怎么查看正在运行的容器和所有容器?

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE           COMMAND       CREATED         STATUS          POR                                                                              TS     NAMES
dd77e4455f76   ubuntu:latest   "/bin/bash"   2 minutes ago   Up 46 seconds                                                                                           test1
f1e29cbd17db   centos:latest   "/bin/bash"   2 minutes ago   Up 45 seconds                                                                                           test2
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE               COMMAND                  CREATED         STAT                                                                              US                    PORTS                                   NAMES
dd77e4455f76   ubuntu:latest       "/bin/bash"              2 minutes ago   Up 5                                                                              1 seconds                                                     test1
f1e29cbd17db   centos:latest       "/bin/bash"              2 minutes ago   Up 5                                                                              0 seconds                                                     test2
4b34386ca0d6   nginx:1.14-alpine   "nginx -g 'daemon of…"   4 weeks ago     Exit                                                                              ed (255) 4 days ago   0.0.0.0:8888->80/tcp, :::8888->80/tcp   web1

6.怎么退出容器: 两种方法分别实现?

root@a992aedce7c0:/# exit
 
或
 
Ctrl + D

7.怎么连接到运行的容器?

[root@localhost ~]# docker exec -it test1 /bin/bash
root@dd77e4455f76:/# exit
exit
[root@localhost ~]# docker exec -it test2 /bin/bash
[root@f1e29cbd17db /]# exit
exit

8.查看容器或镜像的内部信息?

查看容器内部信息
[root@localhost ~]# docker inspect test1
查看镜像内部信息
[root@localhost ~]# docker inspect centos:latest

9.如何查看所有镜像?

[root@localhost ~]# docker images

你可能感兴趣的:(docker,云原生,docker,容器,运维)