Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Compose: Avoid recreation of data container

To update some images I used 'docker-compose pull'. Then I build: 'docker-compose build'.

I wanted only to update the Application Container so I removed it and restarted: 'docker-compose rm app' and 'docker-compose up -d app'.

But something unwanted happened. The data container was recreated too. The old data is lost.

Dockerfile for Datacontainer:

FROM gitlab/gitlab-ce:latest
VOLUME ["/etc/gitlab", "/var/log/gitlab", "/var/opt/gitlab"]
ENTRYPOINT ["hostname"]

docker-compose.yml:

version: '2'
services:
 gitlab:
  image: 'gitlab/gitlab-ce:latest'
  domainname: example.com
  hostname: gitlab
  networks:
   - devenv
  restart: always
  environment:
   GITLAB_OMNIBUS_CONFIG: |
    external_url 'http://gitlab.example.com'
    gitlab_rails['gitlab_shell_ssh_port'] = 2224
  ports:
   - '80:80'
   - '2224:22'
  volumes_from:
   - gitlabdata

 gitlabdata:
  build: gitlab-data

How can I avoid this next time?

like image 883
FalseCAM Avatar asked Sep 04 '26 12:09

FalseCAM


1 Answers

The docker-compose up command has the --no-recreate flag. This flag avoid to recreate containers if they already exists.

Therefore you can run

docker-compose up -d --no-recreate app
like image 191
nessuno Avatar answered Sep 07 '26 07:09

nessuno