Docker ps不显示容器问题

我使用docker 挂载Mysql问题,
开始我使用

docker run -p 3306:3306 --name mysql \ -v /mydata/mysql/log:/var/log/mysql \ -v /mydata/mysql/data:/var/lib/mysql \ -v /mydata/mysql/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:5.7

去挂载发现一直提示我这个
docker: invalid reference format.
See ‘docker run --help’.

[root@localhost ~]# docker run -p 3306:3306 --name mysql \ -v /mydata/mysql/log:/var/log/mysql \ -v /mydata/mysql/data:/var/lib/mysql \ -v /mydata/mysql/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:5.7
docker: invalid reference format.
See 'docker run --help'.

后来我翻看了一下其他人的博客,可以使用 docker ps -a看到所有的容器.我试了下,是有的,但是docker ps 一直都不显示.

[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS                     PORTS     NAMES
921336055b85   mysql:5.7   "docker-entrypoint.s…"   12 minutes ago   Exited (1) 7 seconds ago             mysql

后来使用 docker logs [CONTAINER] 命令看了下日志,大致的意思就是提示我没有配置
- MYSQL_ROOT_PASSWORD
- MYSQL_ALLOW_EMPTY_PASSWORD
- MYSQL_RANDOM_ROOT_PASSWORD
这三个东西.

[root@localhost ~]# docker logs 921336055b85
2022-03-22 17:21:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
2022-03-22 17:21:08+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-03-22 17:21:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
2022-03-22 17:21:09+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
    You need to specify one of the following:
    - MYSQL_ROOT_PASSWORD
    - MYSQL_ALLOW_EMPTY_PASSWORD
    - MYSQL_RANDOM_ROOT_PASSWORD

后面我着重看我的挂载命令,最后终于改好了.我只是把mysql_root_password 这个我改成大写.去掉了"",并且写成一行,如下:

docker run -p 3306:3306 --name mysql -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/config:/etc/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7

最后终于是docker ps 有东西了

[root@localhost ~]# docker run -p 3306:3306 --name mysql -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/config:/etc/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
f428419deb315ed1fc3e6c9d170fd612ae6cee4063d955cfaea91fd7ba85234a
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE       COMMAND                  CREATED         STATUS         PORTS                                                  NAMES
f428419deb31   mysql:5.7   "docker-entrypoint.s…"   6 seconds ago   Up 4 seconds   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql

初次写,记录一下我的心得.

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐