docker容器入门之命令操作

docker服务安装完成后,接下来我们可以进行命令操作
1.首先获取一个镜像,以centos最小镜像为例
使用命令 docker search centos 命令

docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 4553 [OK]
ansible/centos7-ansible Ansible on Centos7 115 [OK]
jdeathe/centos-ssh CentOS-6 6.9 x86_64 / CentOS-7 7.4.1708 x86_… 98 [OK]
consol/centos-xfce-vnc Centos container with “headless” VNC session… 58 [OK]
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 44 [OK]
tutum/centos Simple CentOS docker image with SSH access 43
centos/mysql-57-centos7 MySQL 5.7 SQL database server 35
openshift/base-centos7 A Centos7 derived base image for Source-To-I… 31
gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glust… 31 [OK]
centos/python-35-centos7 Platform for building and running Python 3.5… 27
centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relational … 24
kinogmt/centos-ssh CentOS with SSH 21 [OK]
openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use w… 14
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag names… 6
openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x ima… 4
openshift/wildfly-101-centos7 A Centos7 based WildFly v10.1 image for use … 4
darksheer/centos Base Centos Image – Updated hourly 3 [OK]
pivotaldata/centos Base centos, freshened up a little with a Do… 2
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]
pivotaldata/centos-mingw Using the mingw toolchain to cross-compile t… 1
openshift/wildfly-81-centos7 A Centos7 based WildFly v8.1 image for use w… 1
jameseckersall/sonarr-centos Sonarr on CentOS 7 0 [OK]
pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated wi… 0
smartentry/centos centos with smartentry 0 [OK]

以上列出适合系统的centos镜像

开始获取镜像
docker pull centos
查看镜像信息
docker images

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 49f7960eb7e4 2 months ago 200MB
启动一个容器 centos

docker run -it -d -v /opt:/opt –name=centos_contater centos:latest
参数说明
-it 表示交互模式
-d 表示后台启动
-v 表示启动镜像映射目录 前面的 /opt 表示宿主机目录 后面的 /opt表示镜像所映射的目录

–name 表示给镜像起的名字centos_contater,后面的 centos:latest 表示镜像名

查看容器列表,可看到我们创建过的所有container
docker ps -a
进入容器内部
docker attach 49f7960eb7e4 49f7960eb7e4(表示容器id)

删除镜像,从本地删除一个已经下载的镜像
sudo docker rmi centos:7.2.1511
移除一个或多个容器实例
docker rm (dockerpsaq)dockerkilliddockerrestartiddockerstartiddockerstop ( d o c k e r p s − a − q ) 停 止 一 个 正 在 运 行 的 容 器 d o c k e r k i l l 容 器 i d 重 启 一 个 正 在 运 行 的 容 器 d o c k e r r e s t a r t 容 器 i d 启 动 一 个 容 器 d o c k e r s t a r t 容 器 i d 停 止 所 有 容 器 d o c k e r s t o p (docker ps -a -q)
若是有两个相同id的容器,使用之前方法删除会报错 image is referenced in multiple repositories
docker rmi [REPOSITORY:TAG]
举例:docker rmi centos:latest

以上命令是docker的一些基本操作命令,希望对大家有所帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值