docker 操作镜像的基本操作
Posted zhulina-917
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker 操作镜像的基本操作相关的知识,希望对你有一定的参考价值。
以安装mysql为例
1.拉取镜像
docker pull mysql
错误的启动 [[email protected] ~]# docker run --name mysql01 -d mysql 42f09819908bb72dd99ae19e792e0a5d03c48638421fa64cce5f8ba0f40f5846 mysql退出了 [[email protected] ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42f09819908b mysql "docker-entrypoint.sh" 34 seconds ago Exited (1) 33 seconds ago mysql01 538bde63e500 tomcat "catalina.sh run" About an hour ago Exited (143) About an hour ago compassionate_ goldstine c4f1ac60b3fc tomcat "catalina.sh run" About an hour ago Exited (143) About an hour ago lonely_fermi 81ec743a5271 tomcat "catalina.sh run" About an hour ago Exited (143) About an hour ago sick_ramanujan //错误日志 [[email protected] ~]# docker logs 42f09819908b error: database is uninitialized and password option is not specified You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD;这个三个参数必须指定一个
正确的启动 [[email protected] ~]# docker run --name mysql01 -e MYSQL_ROOT_PASSWORD=123456 -d mysql b874c56bec49fb43024b3805ab51e9097da779f2f572c22c695305dedd684c5f [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b874c56bec49 mysql "docker-entrypoint.sh" 4 seconds ago Up 3 seconds 3306/tcp
做了端口映射 [[email protected] ~]# docker run -p 3306:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=123456 -d mysql ad10e4bc5c6a0f61cbad43898de71d366117d120e39db651844c0e73863b9434 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ad10e4bc5c6a mysql "docker-entrypoint.sh" 4 seconds ago Up 2 seconds 0.0.0.0:3306->3306/tcp my
当关闭后想要再次启动 首先要知道你做了容器映射后的id 找到指定的id,就可以启动容器了
[[email protected] ~]# docker ps -a /etc/sysconfig/docker: line 4: PTIONS: command not found /etc/sysconfig/docker: line 5: /bin/bash:: No such file or directory CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 707b4adac44f mysql "docker-entrypoint..." About an hour ago Up 5 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql02 e705dafeade2 mysql "docker-entrypoint..." About an hour ago Exited (0) About an hour ago mysql01 67d6a8fe057e tomcat "catalina.sh run" 14 hours ago Exited (143) 14 hours ago gracious_cray 72ea521cf5cc tomcat "catalina.sh run" 15 hours ago Exited (143) 14 hours ago mytomcat
执行这一步操作后就可以连接navicate进行数据库操作了。
[[email protected] ~]# docker start 707b4adac44f087 /etc/sysconfig/docker: line 4: PTIONS: command not found /etc/sysconfig/docker: line 5: /bin/bash:: No such file or directory 707b4adac44f087 [[email protected] ~]# docker ps /etc/sysconfig/docker: line 4: PTIONS: command not found /etc/sysconfig/docker: line 5: /bin/bash:: No such file or directory CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 707b4adac44f mysql "docker-entrypoint..." About an hour ago Up 9 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql02
以上是关于docker 操作镜像的基本操作的主要内容,如果未能解决你的问题,请参考以下文章