docker的简单操作

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/wy233333/article/details/94297400

docker的简单操作

  • Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

  • 使用docker的三大理由 :

    1. 无论是安装应用、搭建环境,还是部署应用,都十分的方便灵活。
    2. 节省资源开销。
    3. 灵活的迁移你开发的应用程序。
  • 直接开始

  1. 查看系统的内核版本高于 3.10
    命令查看:uname -r

[root@VM_0_3_centos ~]# uname -r
3.10.0-514.26.2.el7.x86_64

  1. 升级软件包及内核版本
[root@VM_0_3_centos ~]# yum update
  1. 安装docker
//1.安装docker(不知道注释怎么写,就随便用了个双斜杠)
[root@VM_0_3_centos ~]# yum install docker

//2.启动docker
[root@VM_0_3_centos ~]# systemctl start docker

//3.查看版本号
[root@VM_0_3_centos ~]# docker -v
Docker version 1.13.1, build b2f74b2/1.13.1

//4.将docker 服务设为开机启动 
[root@VM_0_3_centos ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

//5.停止docker
[root@VM_0_3_centos ~]# systemctl stop docker
  1. 镜像操作
    Docker检索: https://hub.docker.com/
    Docker 中国官方镜像加速:https://www.docker-cn.com/registry-mirror
//1.检索
//xxx填你需要搜索的,最好去 https://hub.docker.com/搜索
[root@VM_0_3_centos ~]# docker search xxx

//2. 拉取
[root@VM_0_3_centos ~]# docker pull mysql:5.7.26
//可以使用镜像加速
[root@VM_0_3_centos ~]# docker pull registry.docker-cn.com/library/mysql:5.7.26

//3.查看镜像列表
[root@VM_0_3_centos ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/redis     latest              3c41ce05add9        5 days ago          95 MB
docker.io/mysql     5.7.26              7faa3c53e6d6        5 weeks ago         373 MB
[root@VM_0_3_centos ~]#

//4.删除镜像
[root@VM_0_3_centos ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/redis     latest              3c41ce05add9        5 days ago          95 MB
docker.io/mysql     5.7.26              7faa3c53e6d6        5 weeks ago         373 MB
[root@VM_0_3_centos ~]# docker rmi 7faa3c53e6d6
Untagged: docker.io/mysql:5.7.26
Untagged: docker.io/mysql@sha256:196fe3e07006352b4
Deleted: sha256:7faa3c53e6e8013b1fff1c4d9
Deleted: sha256:bada5edfc0f1d4a83c227bc7a153
Deleted: sha256:cb6436ac11f84e3e15073588fc7
[root@VM_0_3_centos ~]#
  1. 容器操作
    详细可以点击下面网站(我也不知道是不是官网)
    https://docs.docker.com/engine/reference/commandline/docker/
//1.运行,比如运行ES
[root@VM_0_3_centos ~]# docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m"
-d -p 9200:9200 -p 9300:9300 --name ES_0617 d0b291d7093b

//2.停止
[root@VM_0_3_centos ~]# docker stop a1bb24e689b8
a1bb24e689b8
[root@VM_0_3_centos ~]#

//3.查看容器日志
[root@VM_0_3_centos ~]# docker logs id

//4启动
[root@VM_0_3_centos ~]# docker start id

//5.删除
[root@VM_0_3_centos ~]# docker rm id

//6.容器列表(这是运行中的)
[root@VM_0_3_centos ~]# docker ps

//7.容器列表(全部)
[root@VM_0_3_centos ~]# docker ps -a
  1. 简单防火墙操作
	//linux系统
	service firewalld status ;查看防火墙状态
	service firewalld stop ;关闭防火墙
希望大家多多点赞

猜你喜欢

转载自blog.csdn.net/wy233333/article/details/94297400