查看Docker容器日志

由于在建立Wordpress容器的时候总是刚建完就直接退出。

[root@hhf ~]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                     PORTS                                      NAMES
da602f603d64        wordpress             "/entrypoint.sh apach"   5 minutes ago       Exited (1) 5 minutes ago                                              wordpress1
dbf9e0ff7cb1        mysql                 "docker-entrypoint.sh"   6 minutes ago       Up 5 minutes               3306/tcp                                   db1

也不知道啥原因,Docker在/var/log下也没有日志。
此时可以使用 docker logs +容器名 查看容器日志

[root@hhf ~]# docker logs da602f603d64
error: missing required WORDPRESS_DB_PASSWORD environment variable
  Did you forget to -e WORDPRESS_DB_PASSWORD=... ?

  (Also of interest might be WORDPRESS_DB_USER and WORDPRESS_DB_NAME.)

原来是没有加 WORDPRESS_DB_PASSWORD 参数导致的
删除创建失败的容器再使用-e WORDPRESS_DB_PASSWORD=’password’创建:

docker rm da602f603d64
docker run --name wordpress1 --link db1:db1 -d -P -e WORDPRESS_DB_PASSWORD=password wordpress
docker ps

CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                      NAMES
dbf9e0ff7cb1        mysql                 "docker-entrypoint.sh"   16 minutes ago      Up 16 minutes       3306/tcp                                   db1
4957dd67d2cd        wordpress             "/entrypoint.sh apach"   44 minutes ago      Up 22 minutes       0.0.0.0:32773->80/tcp                      some-wordpress

附:
docker logs –help

Usage:	docker logs [OPTIONS] CONTAINER

Fetch the logs of a container

Options:
      --details        Show extra details provided to logs
  -f, --follow         Follow log output
      --help           Print usage
      --since string   Show logs since timestamp
      --tail string    Number of lines to show from the end of the logs (default "all")
  -t, --timestamps     Show timestamps

未经允许不得转载:晨飞小窝 » 查看Docker容器日志

赞 (0)

评论 0