Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recreate Docker container?

I'm new to docker and I'm using docker compose. For some reason my postgres container is now broken

I'm trying this command 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

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

Thanks

EDIT 1: If I run docker-compose build && docker-compose up

Terminal throws this:

db uses an image, skipping

EDIT 2: This command does not create database again neither:

docker-compose up --force-recreate --abort-on-container-exit --build db
like image 354
Javier Manzano Avatar asked Apr 20 '17 17:04

Javier Manzano


People also ask

How do I restore a docker container?

Restore your dataUse docker pull to restore images you pushed to Docker Hub. If you backed up your images to a local tar file, use docker image load -i images. tar to restore previously saved images. Re-create your containers if needed, using docker run , or Docker Compose.

Does Docker compose up recreate container?

It turns out that while docker compose up says it recreates the container from the new image and docker compose images & docker container ls shows that a new container with the new image was created, in reality inside the container the old code is running.

How do I reset an existing container?

To restart an existing container, we'll use the start command with the -a flag to attach to it and the -i flag to make it interactive, followed by either the container ID or name. Be sure to substitute the ID of your container in the command below: docker start -ai 11cc47339ee1.


Video Answer


2 Answers

have you tried to rebuild your single postgres container?

docker build -t <postgrescontainer> 

or with docker-compose:

docker-compose up --build

to recreate the images and not use the old 'used' ones.

like image 130
Gabbax0r Avatar answered Oct 10 '22 12:10

Gabbax0r


You can have a look at the images on your system with

docker images

which should show your image, and then

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

you do not know exactly which files were copied, and what thoses files contained

There is also 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)

like image 22
user2915097 Avatar answered Oct 10 '22 13:10

user2915097