docker容器操作

Posted ilifeilong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker容器操作相关的知识,希望对你有一定的参考价值。

docker容器创建

查看当前镜像信息

# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
cenots/centos7-mysql57   latest              d46f0eee5c07        4 hours ago         7.94GB
centos                   version7.1          babd2f913fc9        24 hours ago        262MB
centos                   version7            0f3e07c0138f        2 weeks ago         220MB

创建方式一:docker create

# docker create --name mysql-container --hostname mysql -it cenots/centos7-mysql57 /bin/bash
16986e9a0743c1f856a1ef3d02412793577777b4dde331fad9c611757fcb01d0

[root@sht-sgmhadoopnn-01 ~]# docker ps -a
CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS               NAMES
16986e9a0743        cenots/centos7-mysql57   "/bin/bash"         23 seconds ago      Created                                 mysql-container

通过create命令创建的容器处于stop状态,启动该容器

# docker start mysql-container
mysql-container

# docker ps -a
CONTAINER ID        IMAGE                    COMMAND             CREATED              STATUS              PORTS               NAMES
16986e9a0743        cenots/centos7-mysql57   "/bin/bash"         About a minute ago   Up 3 seconds        3306/tcp            mysql-container

 创建方式二:docker run

# docker run --name mysql7-container --hostname mysql7 -it cenots/centos7-mysql57 /bin/bash

# docker ps
CONTAINER ID        IMAGE                    COMMAND             CREATED             STATUS              PORTS               NAMES
f73cf71d3e8e        cenots/centos7-mysql57   "/bin/bash"         11 seconds ago      Up 9 seconds        3306/tcp            mysql7-container
16986e9a0743        cenots/centos7-mysql57   "/bin/bash"         4 minutes ago       Up 2 minutes        3306/tcp            mysql-container

 

 通过run命令创建的容器处于running状态

 进入docker容器

# docker exec -it mysql-container /bin/bash
bash-4.4$ hostname
mysql

 

以上是关于docker容器操作的主要内容,如果未能解决你的问题,请参考以下文章

使用 vs 代码对本机 docker 容器做出反应以发布到主机操作系统上的 android 模拟器

Docker容器学习--1

Docker基础操作

Docker基础操作

Docker容器

Docker——Docker组件Docker安装与启动