timiTao
timiTao

Reputation: 1413

Using same containers with multiple project on local host

Problem

A have few projects on my computer, that all are developed.

I started working with docker few month ago and I share some config between projects.

I have clear container list each time. Why? Because usually my process need to look like:

  1. Delete all containers docker rm $(docker ps -a -q)
  2. Delete all images - docker rmi $(docker images -q)
  3. run docker-compose up -d

The problem is everywhere, I have defined composer (like in config below). When I switch, but don't delete images/containers, then i have, that composer/composer container exist and don't start.

Of course, I use more services like that, but this is simples one.

docker-compose.yml

version: '2'
services:
  php:
    image: php:7.1.3-alpine
    volumes:
      - ./:/app
    working_dir: /app
  composer:
    image: composer/composer
    volumes_from:
      - php
    working_dir: /app

My env

Till now

Summary

As the topic is to wide, to many pages. Maybe I ommited something in understand of concept or config.

Would be nice to get some explanation and hints for good manage docker-compose.yml files like that and what was wrong in my process.

Thanks.

Upvotes: 0

Views: 405

Answers (1)

Brian from QuantRocket
Brian from QuantRocket

Reputation: 5493

Your question isn't very clear, but it sounds like you're using docker-compose to bring the containers up but relying on docker rm/docker rmi to take them down. Try doing everything with Docker Compose. Bring services up:

docker-compose up -d

Take services down but let volumes persist:

docker-compose down

Take services down and destroy volumes:

docker-compose down --volumes

https://docs.docker.com/compose/reference/down/

For the compose file you posted, you shouldn't generally need to use docker rm/docker rmi.

Upvotes: 4

Related Questions