Running copies of the same application with multiple containers using Docker Compose

Problem

I want to run webapp through Docker, running 2 containers as a unit.

1 container starts my web server (Tomcat 7).

Another container runs my database (Postgres 9.4).

I can start docker-compose up, and Docker can expand my two containers, as indicated in mine docker-compose.yml:

web:                                                                                     
  build: .                                                                         
  ports:                                                                           
   - "5000"                                                                        
  links:                                                                           
   - db                                                                         
db:                                                                             
  image: postgres

I want to be able to deploy another copy of my webapp by launching again docker-compose up, but this leads to the fact that Docker tells me that the containers are already running:

$ docker-compose up -d
Creating composetest_db_1
Creating composetest_web_1
$ docker-compose up -d
composetest_db_1 is up-to-date
composetest_web_1 is up-to-date

My job

I circumvented this problem by using the option -pto give new copies different names for the projects:

$ docker-compose -p project1 up -d
...
Successfully built d3268e345f3d
Creating project1_web_1
$ docker-compose -p project2 up -d
...
Successfully built d3268e345f3d
Creating project2_web_1

Unfortunately, this creates new images for each copy:

$ docker images
project1_web          latest              d3268e345f3d        2 hours ago         682 MB
project2_web          latest              d3268e345f3d        2 hours ago         682 MB

Question

docker-compose ?

+4
2

, compose script.

run docker build -t somewebapp/web:latest ,

docker-compose.yml .

+1

, ( ):

$ docker-compose --project-name inst1 up -d
Creating inst1_web_1

$ docker-compose --project-name inst2 up -d
Creating inst2_web_1

:

$ docker-compose --project-name inst2 scale web=5
Creating and starting 2 ... done
Creating and starting 3 ... done
Creating and starting 4 ... done
Creating and starting 5 ... done

6 :

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                     NAMES
5e4ab4cebacf        tomcat:8.0          "catalina.sh run"   43 seconds ago      Up 42 seconds       0.0.0.0:32772->8080/tcp   inst2_web_2
ced61f9ac2db        tomcat:8.0          "catalina.sh run"   43 seconds ago      Up 42 seconds       0.0.0.0:32773->8080/tcp   inst2_web_5
efb1ef13147c        tomcat:8.0          "catalina.sh run"   43 seconds ago      Up 42 seconds       0.0.0.0:32771->8080/tcp   inst2_web_4
58e524da3473        tomcat:8.0          "catalina.sh run"   43 seconds ago      Up 42 seconds       0.0.0.0:32770->8080/tcp   inst2_web_3
0f58c3c3b0ed        tomcat:8.0          "catalina.sh run"   2 minutes ago       Up 2 minutes        0.0.0.0:32769->8080/tcp   inst2_web_1
377e3e5b03e4        tomcat:8.0          "catalina.sh run"   2 minutes ago       Up 2 minutes        0.0.0.0:32768->8080/tcp   inst1_web_1
+2

Source: https://habr.com/ru/post/1618730/


All Articles