0

I have an application composed of a front end, a back end and a mongodb database, each of these dockerized in a container. When I build them with docker compose I have as many images as parts in my application (3).

Is there any way to build a single container from these 3 images and therefore a single image?

Thanks

MrSkineto
  • 3
  • 2
  • 1
    Possible duplicate of [Running multiple applications in one docker container](https://stackoverflow.com/questions/27664820/running-multiple-applications-in-one-docker-container). Side note: you could, but don't do this. Period – Mike Doe Apr 23 '18 at 12:21
  • That's not Docker way. If I understand correctly you want to create single image so that you don't need to build them separately and deploy three MSs each time. Is that correct? – Ubercool Apr 23 '18 at 12:33
  • Yeah, it's correct. I want that – MrSkineto Apr 23 '18 at 12:50
  • You should really either create a kubernetes pod or docker-compose with each app being an app. Then, you can deploy all three in a single command – ealeon Apr 24 '18 at 03:44

2 Answers2

1

You can write a Dockerfile if you want to run your application as a single container. it will give you single image as well.

Aditya Pawaskar
  • 243
  • 4
  • 11
  • That is true. But it is generally not a good idea to do this. It is best to have a bunch of containers where each one of them does one thing and does it well. Almost like the unix philosophy behind unix commands. – OpenBSDNinja Apr 23 '18 at 13:06
  • yes, absolutely. but without Dockerfile and docker compose how will question solve? – Aditya Pawaskar Apr 23 '18 at 13:09
0

I guess you could do this if you really wanted to. The preferred way is to use docker-compose for this. I would suggest that you create a docker-compose.yml file that helps you setup this:

nginx->frontend (possibly with server side rendering) -> backend -> mongodb

The idea behind docker-compose is to easily get that multi container application up and running using a docker-compose.yml file , then you can just bring up the application with:

$ docker-compose up

You could it setup with something like this: (This is a hypothetical docker-compose.yml file, but with your correct values it should work. Let me know if you have any questions:

version: '2'
services:
  frontend-container:
    image: frontend:latest
    links:
      - backend-container
    environment:
      - DEBUG=True
    restart: always
    environment:
      - BASE_HOST=http://backend-container:8000/



  backend-container:
    image: nodejs-backend:latest
    links:
      - mongodb
    environment:
      - NODE_ENV=production
      - BASE_HOST=http://django-container:8000/
    restart: always

    mongodb:
        image: mongo:latest
        container_name: "mongodb"
        environment:
          - MONGO_DATA_DIR=/data/db
          - MONGO_LOG_DIR=/dev/null
        volumes:
          - ./data/db:/data/db
        command: mongod --smallfiles --logpath=/dev/null



  nginx-container:
    image: nginx-container-custom-config:latest
    links:
      - frontend-container
    ports:
      - "80:80"
OpenBSDNinja
  • 1,037
  • 10
  • 18
  • I think he have already a compose file. But he wants all his application in one container. Strange – Kilian Apr 23 '18 at 12:40
  • Ya, thanks for your responses. I already have a docker compose functional but when I do docker-compose up i have 3 images in 3 containers, I need just one container with single image – MrSkineto Apr 23 '18 at 12:54