postgresql 如何重新创建 Docker 容器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43526072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to recreate Docker container?
提问by Javier Manzano
I'm new to docker and I'm using docker compose. For some reason my postgres container is now broken
我是 docker 新手,我正在使用 docker compose。出于某种原因,我的 postgres 容器现在坏了
I'm trying this command docker-compose up --no-deps --build db
我正在尝试这个命令 docker-compose up --no-deps --build db
And it's returning me this:
它返回给我:
MacBook-Pro-de-Javier:goxo.api javier$ docker-compose up --no-deps --build db
Recreating testapi_db_1
Attaching to testapi_db_1
db_1 | LOG: database system was shut down at 2017-04-20 17:19:05 UTC
db_1 | LOG: MultiXact member wraparound protections are now enabled
db_1 | LOG: database system is ready to accept connections
db_1 | LOG: autovacuum launcher started
Whenever I try to connect (with the same connection arguemnts than before) I get this:
每当我尝试连接(使用与以前相同的连接参数)时,我都会得到以下信息:
^[[Adb_1 | FATAL: database "test" does not exist
This is part of my docker-compose.yml
这是我的 docker-compose.yml 的一部分
version: "3"
services:
db:
image: postgres
ports:
- "3700:5432"
environment:
POSTGRES_HOST: "127.0.0.1"
POSTGRES_DB: "test"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres1"
tmpfs:
- /tmp
- /var/run/postgresql
volumes:
- db:/var/lib/postgresql/data
- ./config/postgres-initdb.sh:/docker-entrypoint-initdb.d/initdb.sh
Any ideas on how can I recreate the docker image to be how it was before? It was working as it was created the first time
关于如何重新创建 docker 镜像的任何想法?它在第一次创建时正常工作
Thanks
谢谢
EDIT 1:If I run docker-compose build && docker-compose up
编辑 1:如果我跑docker-compose build && docker-compose up
Terminal throws this:
终端抛出这个:
db uses an image, skipping
EDIT 2:This command does not create database again neither:
编辑 2:此命令不会再次创建数据库:
docker-compose up --force-recreate --abort-on-container-exit --build db
回答by Gabbax0r
have you tried to rebuild your single postgres container?
您是否尝试过重建您的单个 postgres 容器?
docker build -t <postgrescontainer>
or with docker-compose:
或使用 docker-compose:
docker-compose up --build
to recreate the images and not use the old 'used' ones.
重新创建图像,而不是使用旧的“使用过的”图像。
回答by user2915097
You can have a look at the images on your system with
您可以使用以下命令查看系统上的图像
docker images
docker images
which should show your image, and then
这应该显示你的形象,然后
docker history --no-trunc your_image
docker history --no-trunc your_image
should show the commands used for the creation of the image
应该显示用于创建图像的命令
This my be insufficient, as when you see something like
这我是不够的,因为当你看到类似的东西时
ADD * /opt
ADD * /opt
you do not know exactly which files were copied, and what thoses files contained
您不确切知道复制了哪些文件,以及这些文件包含哪些内容
There is also dockerfile-from-image
还有 dockerfile-from-image
https://github.com/CenturyLinkLabs/dockerfile-from-image
https://github.com/CenturyLinkLabs/dockerfile-from-image
which seems to have a bug recently (I do not know if it is fixed)
最近好像有个bug(不知道有没有修复)