简体   繁体   English

如何重新启动停止的 docker 容器?

[英]How to restart a stopped docker container?

I have pulled a postgres image and created a docker container called pgdb , which has exited.我提取了一个postgres映像并创建了一个名为pgdb的 docker 容器,该容器已退出。 Here is what the terminal returns after typing docker ps -all :这是输入docker ps -all后终端返回的内容:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
e62fdb45c727        postgres            "docker-entrypoint.s…"   19 hours ago        Exited (1) 14 minutes ago                       pgdb

now I am trying to restart my container by typing docker exec -it pgdb bash , however I am getting the following error message: Error response from daemon: Container e62fdb45c727baf9ca9d7b55401f870b35959a10f356a401f058f2e693adc2fd is not running now I am trying to restart my container by typing docker exec -it pgdb bash , however I am getting the following error message: Error response from daemon: Container e62fdb45c727baf9ca9d7b55401f870b35959a10f356a401f058f2e693adc2fd is not running

I tried to attach the container like so:我试图像这样附加容器:

random@random-142:~$ sudo docker start pgdb
pgdb
random@random-142:~$ sudo docker attach pgdb
You cannot attach to a stopped container, start it first

but it also didnt work.但它也没有用。 Does anyone know how I could go about solving this?有谁知道我如何解决这个问题? I am really desperate.我真的很绝望。

EDIT编辑

container logs容器日志

random@random-142:~$ sudo docker logs pgdb
Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD to a non-empty value for the
       superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

       You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
       connections without a password. This is *not* recommended.

       See PostgreSQL documentation about "trust":
       https://www.postgresql.org/docs/current/auth-trust.html
Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD to a non-empty value for the
       superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

       You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
       connections without a password. This is *not* recommended.

       See PostgreSQL documentation about "trust":
       https://www.postgresql.org/docs/current/auth-trust.html

The docker container logs itself are self-explanatory. docker 容器日志本身是不言自明的。 You need to specify the database and superuser password.您需要指定数据库和超级用户密码。

Add the following arguments while running your Postgres docker container:在运行 Postgres docker 容器时添加以下 arguments:

-e "POSTGRES_DB=YOUR_DB_NAME" -e "POSTGRES_PASSWORD=YOUR_PASSWORD"

Example:例子:

docker run -itd -p 5432:5432 -e "POSTGRES_DB=testdb" -e "POSTGRES_PASSWORD=password" --name pgdb postgres

If you are not willing to add any password, then use "POSTGRES_HOST_AUTH_METHOD=trust" .如果您不愿意添加任何密码,请使用"POSTGRES_HOST_AUTH_METHOD=trust" Example:例子:

docker run -itd -p 5432:5432 -e "POSTGRES_DB=testdb" -e "POSTGRES_HOST_AUTH_METHOD=trust" --name pgdb postgres

To restart the container you can use this command要重新启动容器,您可以使用此命令

docker start -ai "container_name"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM