Docker ps 不显示使用 docker-compose 创建/运行的容器



我试图理解为什么我看不到使用docker ps使用docker compose-up-d创建的容器。如果我转到docker-compose.yaml所在的文件夹并运行docker-compose-ps,我可以看到容器正在运行。我在windows上也这样做了,因为我使用的是ubuntu,它按预期工作,我可以看到容器正在运行docker ps。有人能给我一个关于这种行为的提示吗?提前谢谢。

Environment:
Docker version 20.10.17, build 100c701
docker-compose version 1.25.0, build unknown
Ubuntu 20.04.4 LTS

在我的终端中,我看到这个输出:

/GIT/project$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
/GIT/project$ cd scripts/
/GIT/project/scripts$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
/GIT/project/scripts$ docker-compose ps
Name                  Command               State                       Ports                    
-----------------------------------------------------------------------------------------------------
scripts_db_1   docker-entrypoint.sh --def ...   Up      0.0.0.0:3306->3306/tcp,:::3306->3306/tcp,    
33060/tcp                                    
/GIT/project/scripts$ 

docker-compose.yaml

version: '3.3'
services:
db:
image: mysql:5.7
# NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
# (this is just an example, not intended to be a production configuration)
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
# <Port exposed> : < MySQL Port running inside container>
- 3306:3306
expose:
# Opens port 3306 on the container
- 3306
# Where our data will be persisted
volumes:
- treip:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: changeit
MYSQL_DATABASE: treip
volumes:
treip:

我用sudo执行了容器,问题得到了解决。现在容器使用docker ps,所以我用sudosudo docker-compose up执行它而不是docker-compose up。对不起,我的错。

相关内容

  • 没有找到相关文章

最新更新