docker安装配置

一、docker安装配置

修改主机名

[ ~]#vi /etc/hostname

查看Linux系统信息

[ ~]# cat /etc/redhat-release   #查看版本号
CentOS Linux release 7.7.1908 (Core)

[ ~]# uname -r      #查看linux内核
3.10.0-1062.el7.x86_64

替换为阿里云yum源

[ ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  #替换为阿里云yum

[ ~]# yum makecache    #生成缓存仓库

安装docker

[ ~]# yum install docker -y

启动docker

[ ~]# systemctl start docker      #启动docker
[ ~]# systemctl enable docker    #添加开机启动
[ ~]# systemctl status docker     #查看docker状态

查看docker版本

[ ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-161.git64e9980.el7_8.x86_64
 Go version:      go1.10.3
 Git commit:      64e9980/1.13.1
 Built:           Tue Apr 28 14:43:01 2020
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-161.git64e9980.el7_8.x86_64
 Go version:      go1.10.3
 Git commit:      64e9980/1.13.1
 Built:           Tue Apr 28 14:43:01 2020
 OS/Arch:         linux/amd64
 Experimental:    false

比如装nginx,从公有镜像查找,下载

[ ~]# docker search nginx
INDEX       NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/nginx                              Official build of Nginx.                        13212     [OK]

[ ~]# docker pull nginx
Using default tag: latest
Trying to pull repository docker.io/library/nginx ...
latest: Pulling from docker.io/library/nginx
afb6ec6fdc1c: Pull complete
b90c53a0b692: Pull complete
11fa52a0fdc0: Pull complete
Digest: sha256:30dfa439718a17baafefadf16c5e7c9d0a1cde97b4fd84f63b69e13513be7097
Status: Downloaded newer image for docker.io/nginx:latest

[ ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/nginx     latest              9beeba249f3e        6 days ago          127 MB

启动nginx镜像

[ ~]# docker run -p 8000:80 --name mynginx -d nginx     ##-p指定服务器8000端口,映射容器80端口,容器名为mynginx,-d使用守护进程模式启动
886c281c102a68484f0788ad878b776cc609a8cd46af644d3e011859b48c2605

[ ~]# docker ps    #查看目前工作的容器
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
886c281c102a        nginx               "nginx -g ‘daemon ..."   33 seconds ago      Up 33 seconds       0.0.0.0:8000->80/tcp   mynginx
[ ~]# docker ps -a    #查看所有已运行的容器
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
886c281c102a        nginx               "nginx -g ‘daemon ..."   41 seconds ago      Up 40 seconds       0.0.0.0:8000->80/tcp   mynginx

nginx已启动,此时可访问服务器IP地址加映射后的端口8000,即可访问到nginx服务页面

docker安装配置

也可使用exec命令进入容器系统查看

[ ~]# docker exec -it 886c281c102a  /bin/bash
:/#                 #主机名已发生变化

二、卸载docker

查询docker安装过的包

[ ~]# yum list installed | grep docker
docker.x86_64                           2:1.13.1-161.git64e9980.el7_8  @extras
docker-client.x86_64                    2:1.13.1-161.git64e9980.el7_8  @extras
docker-common.x86_64                    2:1.13.1-161.git64e9980.el7_8  @extras

删除已安装的包

[ ~]# yum remove docker.x86_64 docker-client.x86_64 docker-common.x86_64 -y

删除容器及镜像

[ ~]# rm -rf /var/lib/docker/

相关推荐